From 464126195df84c1a4583ce336959e1cb59dda579 Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Sun, 1 Feb 2026 21:47:56 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=96=AD=E5=A5=B6=E5=BD=95=E5=85=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E6=96=AD=E5=A5=B6=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=B9=B2=E5=A5=B6=E5=BD=95=E5=85=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=B9=B2=E5=A5=B6=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E6=AD=BB=E4=BA=A1=E5=BD=95=E5=85=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E6=AD=BB=E4=BA=A1=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../breed/controller/ScDryMilkController.java | 229 ++++---------- .../controller/ScSheepDeathController.java | 166 +++------- .../controller/ScWeanRecordController.java | 65 +--- .../produce/breed/domain/ScDryMilk.java | 14 +- .../produce/breed/domain/ScSheepDeath.java | 298 +++++------------- .../produce/breed/domain/ScWeanRecord.java | 30 +- .../produce/breed/mapper/ScDryMilkMapper.java | 46 ++- .../breed/mapper/ScSheepDeathMapper.java | 39 ++- .../breed/mapper/ScWeanRecordMapper.java | 40 ++- .../breed/service/IScDryMilkService.java | 39 +-- .../breed/service/IScSheepDeathService.java | 31 +- .../breed/service/IScWeanRecordService.java | 35 +- .../service/impl/ScDryMilkServiceImpl.java | 93 ++---- .../service/impl/ScSheepDeathServiceImpl.java | 152 +++------ .../service/impl/ScWeanRecordServiceImpl.java | 102 +++--- .../mapper/produce/breed/ScDryMilkMapper.xml | 35 +- .../produce/breed/ScSheepDeathMapper.xml | 118 +++++-- .../produce/breed/ScWeanRecordMapper.xml | 58 ++-- 18 files changed, 628 insertions(+), 962 deletions(-) diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScDryMilkController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScDryMilkController.java index b449d88..c308db0 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScDryMilkController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScDryMilkController.java @@ -1,7 +1,8 @@ package com.zhyc.module.produce.breed.controller; +import java.util.Arrays; import java.util.List; -import java.util.Map; +import java.util.ArrayList; import javax.servlet.http.HttpServletResponse; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; @@ -27,8 +28,7 @@ import com.zhyc.common.core.page.TableDataInfo; /** * 干奶记录Controller - * - * @author ruoyi + * * @author ruoyi * @date 2025-07-15 */ @RestController @@ -49,24 +49,37 @@ public class ScDryMilkController extends BaseController public TableDataInfo list(ScDryMilk scDryMilk) { try { - // 添加调试日志 + // 兼容逻辑:如果前端传了字符串形式的耳号(如导出或老接口调用),也转为List if (scDryMilk.getManageTags() != null && !scDryMilk.getManageTags().trim().isEmpty()) { - logger.info("搜索耳号参数: [{}]", scDryMilk.getManageTags()); - scDryMilk.setManageTags(scDryMilk.getManageTags().trim()); + if (scDryMilk.getManageTagsList() == null) { + scDryMilk.setManageTagsList(new ArrayList<>()); + } + // 支持中文逗号、英文逗号、空格分割 + String[] tags = scDryMilk.getManageTags().trim().split("[,,\\s]+"); + scDryMilk.getManageTagsList().addAll(Arrays.asList(tags)); } startPage(); List list = scDryMilkService.selectScDryMilkList(scDryMilk); - - logger.info("查询到干奶记录数量: {}", list.size()); - return getDataTable(list); } catch (Exception e) { logger.error("查询干奶记录列表失败", e); - return getDataTable(new java.util.ArrayList<>()); + return getDataTable(new ArrayList<>()); } } + /** + * 远程搜索耳号列表 + */ + @GetMapping("/searchEarNumbers") + public AjaxResult searchEarNumbers(@RequestParam(value = "query", required = false) String query) + { + if (query == null) query = ""; + // 调用Service层 + List list = scDryMilkService.selectSheepEarNumberList(query); + return AjaxResult.success(list); + } + /** * 导出干奶记录列表 */ @@ -77,9 +90,9 @@ public class ScDryMilkController extends BaseController { try { if (scDryMilk.getManageTags() != null) { - scDryMilk.setManageTags(scDryMilk.getManageTags().trim()); + String[] tags = scDryMilk.getManageTags().trim().split("[,,\\s]+"); + scDryMilk.setManageTagsList(Arrays.asList(tags)); } - List list = scDryMilkService.selectScDryMilkList(scDryMilk); ExcelUtil util = new ExcelUtil(ScDryMilk.class); util.exportExcel(response, list, "干奶记录数据"); @@ -95,86 +108,17 @@ public class ScDryMilkController extends BaseController @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { - try { - if (id == null) { - return error("记录ID不能为空"); - } - - ScDryMilk result = scDryMilkService.selectScDryMilkById(id); - if (result == null) { - return error("记录不存在"); - } - - return success(result); - } catch (Exception e) { - logger.error("获取干奶记录详细信息失败,ID: " + id, e); - return error("获取记录详细信息失败: " + e.getMessage()); - } + return success(scDryMilkService.selectScDryMilkById(id)); } /** - * 根据耳号查询羊只ID - 新增耳号验证功能 - */ - @GetMapping("/validateEarTag") - public AjaxResult validateEarTag(@RequestParam("manageTags") String manageTags) - { - try { - if (manageTags == null || manageTags.trim().isEmpty()) { - return error("耳号不能为空"); - } - - String cleanTag = manageTags.trim(); - logger.info("验证耳号: [{}]", cleanTag); - - Long sheepId = scDryMilkService.selectSheepIdByManageTags(cleanTag); - if (sheepId == null) { - logger.warn("耳号 [{}] 不存在", cleanTag); - return error("该耳号不存在,请检查输入"); - } - - logger.info("验证耳号成功,羊只ID: {}", sheepId); - return AjaxResult.success("耳号验证通过", sheepId); - } catch (Exception e) { - logger.error("验证耳号失败,耳号: " + manageTags, e); - return error("验证耳号时出错: " + e.getMessage()); - } - } - - /** - * 根据耳号查询羊只ID - */ - @PreAuthorize("@ss.hasPermi('drymilk:drymilk:query')") - @GetMapping(value = "/sheep/{manageTags}") - public AjaxResult getSheepIdByManageTags(@PathVariable("manageTags") String manageTags) - { - Long sheepId = scDryMilkService.selectSheepIdByManageTags(manageTags); - return success(sheepId); - } - - /** - * 获取羊舍列表 - 用于嵌套选择 + * 获取羊舍列表 */ @GetMapping("/sheepfoldList") - public AjaxResult getSheepfoldList(@RequestParam(value = "ranchId", required = false) Long ranchId, - @RequestParam(value = "sheepfoldTypeId", required = false) Long sheepfoldTypeId) + public AjaxResult getSheepfoldList(DaSheepfold daSheepfold) { - try { - DaSheepfold query = new DaSheepfold(); - if (ranchId != null) { - query.setRanchId(ranchId); - } - if (sheepfoldTypeId != null) { - query.setSheepfoldTypeId(sheepfoldTypeId); - } - - List sheepfoldList = daSheepfoldService.selectDaSheepfoldList(query); - logger.info("查询羊舍列表,牧场ID: {}, 类型ID: {}, 结果数量: {}", ranchId, sheepfoldTypeId, sheepfoldList.size()); - - return success(sheepfoldList); - } catch (Exception e) { - logger.error("获取羊舍列表失败", e); - return error("获取羊舍列表失败: " + e.getMessage()); - } + List list = daSheepfoldService.selectDaSheepfoldList(daSheepfold); + return success(list); } /** @@ -186,43 +130,41 @@ public class ScDryMilkController extends BaseController public AjaxResult add(@RequestBody ScDryMilk scDryMilk) { try { - // 基础参数校验 - if (scDryMilk == null) { - return error("请求参数不能为空"); - } - - if (scDryMilk.getManageTags() == null || scDryMilk.getManageTags().trim().isEmpty()) { + if (scDryMilk == null || scDryMilk.getManageTags() == null) { return error("耳号不能为空"); } - if (scDryMilk.getDatetime() == null) { - return error("干奶日期不能为空"); + // 批量解析耳号 + String[] tags = scDryMilk.getManageTags().trim().split("[\\s,,\n]+"); + int successCount = 0; + StringBuilder errorMsg = new StringBuilder(); + + for (String tag : tags) { + if (tag.isEmpty()) continue; + + Long sheepId = scDryMilkService.selectSheepIdByManageTags(tag); + if (sheepId == null) { + errorMsg.append(tag).append("不存在; "); + continue; + } + + ScDryMilk newItem = new ScDryMilk(); + newItem.setSheepId(String.valueOf(sheepId)); + newItem.setDatetime(scDryMilk.getDatetime()); + newItem.setStatus(scDryMilk.getStatus()); + newItem.setSheepfold(scDryMilk.getSheepfold()); + newItem.setTecahnician(scDryMilk.getTecahnician()); + newItem.setComment(scDryMilk.getComment()); + newItem.setCreateBy(getUsername()); + + scDryMilkService.insertScDryMilk(newItem); + successCount++; } - if (scDryMilk.getStatus() == null) { - return error("请选择是否使用乳头封闭剂"); - } - - // 清理输入参数 - scDryMilk.setManageTags(scDryMilk.getManageTags().trim()); - if (scDryMilk.getTecahnician() != null) { - scDryMilk.setTecahnician(scDryMilk.getTecahnician().trim()); - } - if (scDryMilk.getComment() != null) { - scDryMilk.setComment(scDryMilk.getComment().trim()); - } - - logger.info("新增干奶记录,耳号: {}", scDryMilk.getManageTags()); - - int result = scDryMilkService.insertScDryMilk(scDryMilk); - if (result > 0) { - // 重新查询插入的记录,包含自动生成的创建时间 - ScDryMilk insertedRecord = scDryMilkService.selectScDryMilkById(scDryMilk.getId()); - logger.info("新增干奶记录成功,记录ID: {}", scDryMilk.getId()); - return success(insertedRecord); - } else { - return error("新增失败"); + if (errorMsg.length() > 0) { + return warn("成功录入 " + successCount + " 条。失败详情:" + errorMsg.toString()); } + return success("成功录入 " + successCount + " 条记录"); } catch (Exception e) { logger.error("新增干奶记录失败", e); return error("新增失败: " + e.getMessage()); @@ -237,39 +179,7 @@ public class ScDryMilkController extends BaseController @PutMapping public AjaxResult edit(@RequestBody ScDryMilk scDryMilk) { - try { - if (scDryMilk == null) { - return error("请求参数不能为空"); - } - - if (scDryMilk.getId() == null) { - return error("记录ID不能为空"); - } - - // 清理输入参数 - if (scDryMilk.getManageTags() != null) { - scDryMilk.setManageTags(scDryMilk.getManageTags().trim()); - } - if (scDryMilk.getTecahnician() != null) { - scDryMilk.setTecahnician(scDryMilk.getTecahnician().trim()); - } - if (scDryMilk.getComment() != null) { - scDryMilk.setComment(scDryMilk.getComment().trim()); - } - - logger.info("修改干奶记录,ID: {}", scDryMilk.getId()); - - int result = scDryMilkService.updateScDryMilk(scDryMilk); - if (result > 0) { - logger.info("修改干奶记录成功"); - return success("修改成功"); - } else { - return error("修改失败,记录可能不存在"); - } - } catch (Exception e) { - logger.error("修改干奶记录失败", e); - return error("修改失败: " + e.getMessage()); - } + return toAjax(scDryMilkService.updateScDryMilk(scDryMilk)); } /** @@ -280,23 +190,6 @@ public class ScDryMilkController extends BaseController @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { - try { - if (ids == null || ids.length == 0) { - return error("删除的记录ID不能为空"); - } - - logger.info("删除干奶记录,IDs: {}", java.util.Arrays.toString(ids)); - - int result = scDryMilkService.deleteScDryMilkByIds(ids); - if (result > 0) { - logger.info("删除干奶记录成功,删除数量: {}", result); - return success("删除成功"); - } else { - return error("删除失败,记录可能不存在"); - } - } catch (Exception e) { - logger.error("删除干奶记录失败", e); - return error("删除失败: " + e.getMessage()); - } + return toAjax(scDryMilkService.deleteScDryMilkByIds(ids)); } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScSheepDeathController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScSheepDeathController.java index 229cd5a..8a62b95 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScSheepDeathController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScSheepDeathController.java @@ -12,12 +12,12 @@ 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.common.exception.ServiceException; import com.zhyc.module.produce.breed.domain.ScSheepDeath; import com.zhyc.module.produce.breed.service.IScSheepDeathService; import com.zhyc.module.biosafety.service.ISwDiseaseService; @@ -48,19 +48,35 @@ public class ScSheepDeathController extends BaseController @GetMapping("/list") public TableDataInfo list(ScSheepDeath scSheepDeath) { - try { - startPage(); - List list = scSheepDeathService.selectScSheepDeathList(scSheepDeath); - return getDataTable(list); - } catch (Exception e) { - logger.error("查询羊只死淘记录列表失败", e); - return getDataTable(new java.util.ArrayList<>()); - } + startPage(); + List list = scSheepDeathService.selectScSheepDeathList(scSheepDeath); + return getDataTable(list); } /** - * 根据管理耳号查询羊只信息 + * 搜索管理耳号(用于下拉提示) */ + @GetMapping("/search/earNo") + public AjaxResult searchEarNo(@RequestParam("query") String query) { + return success(scSheepDeathService.selectDistinctManageTags(query == null ? "" : query)); + } + + /** + * 搜索技术员(用于下拉提示) + */ + @GetMapping("/search/technician") + public AjaxResult searchTechnician(@RequestParam("query") String query) { + return success(scSheepDeathService.selectDistinctTechnician(query == null ? "" : query)); + } + + /** + * 搜索处理人(用于下拉提示) + */ + @GetMapping("/search/handler") + public AjaxResult searchHandler(@RequestParam("query") String query) { + return success(scSheepDeathService.selectDistinctHandler(query == null ? "" : query)); + } + @PreAuthorize("@ss.hasPermi('sheep_death:death:query')") @GetMapping("/sheepInfo/{manageTags}") public AjaxResult getSheepInfo(@PathVariable("manageTags") String manageTags) @@ -69,7 +85,6 @@ public class ScSheepDeathController extends BaseController if (manageTags == null || manageTags.trim().isEmpty()) { return error("管理耳号不能为空"); } - Map sheepInfo = scSheepDeathService.selectSheepFileByManageTags(manageTags.trim()); if (sheepInfo != null) { return success(sheepInfo); @@ -77,172 +92,63 @@ public class ScSheepDeathController extends BaseController return error("未找到该耳号对应的羊只信息"); } } catch (Exception e) { - logger.error("查询羊只信息失败,管理耳号: " + manageTags, e); return error("查询羊只信息失败: " + e.getMessage()); } } - /** - * 获取疾病树形列表 - */ @PreAuthorize("@ss.hasPermi('sheep_death:death:query')") @GetMapping("/disease/tree") public AjaxResult getDiseaseTree() { - try { - List diseaseList = swDiseaseService.selectSwDiseaseList(new SwDisease()); - return success(diseaseList); - } catch (Exception e) { - logger.error("获取疾病树形列表失败", e); - return error("获取疾病列表失败: " + e.getMessage()); - } + List diseaseList = swDiseaseService.selectSwDiseaseList(new SwDisease()); + return success(diseaseList); } - /** - * 导出羊只死淘记录列表 - */ @PreAuthorize("@ss.hasPermi('sheep_death:death:export')") @Log(title = "羊只死淘记录", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, ScSheepDeath scSheepDeath) { - try { - List list = scSheepDeathService.selectScSheepDeathList(scSheepDeath); - ExcelUtil util = new ExcelUtil(ScSheepDeath.class); - util.exportExcel(response, list, "羊只死淘记录数据"); - } catch (Exception e) { - logger.error("导出羊只死淘记录失败", e); - // 可以在这里返回错误响应 - } + List list = scSheepDeathService.selectScSheepDeathList(scSheepDeath); + ExcelUtil util = new ExcelUtil(ScSheepDeath.class); + util.exportExcel(response, list, "羊只死淘记录数据"); } - /** - * 获取羊只死淘记录详细信息 - */ @PreAuthorize("@ss.hasPermi('sheep_death:death:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { - try { - if (id == null) { - return error("记录ID不能为空"); - } - - ScSheepDeath result = scSheepDeathService.selectScSheepDeathById(id); - if (result == null) { - return error("记录不存在"); - } - - return success(result); - } catch (Exception e) { - logger.error("获取羊只死淘记录详细信息失败,ID: " + id, e); - return error("获取记录详细信息失败: " + e.getMessage()); - } + return success(scSheepDeathService.selectScSheepDeathById(id)); } - /** - * 新增羊只死淘记录 - */ @PreAuthorize("@ss.hasPermi('sheep_death:death:add')") @Log(title = "羊只死淘记录", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody ScSheepDeath scSheepDeath) { try { - // 基础参数校验 - if (scSheepDeath == null) { - return error("请求参数不能为空"); - } - - if (scSheepDeath.getManageTags() == null || scSheepDeath.getManageTags().trim().isEmpty()) { + if (scSheepDeath == null || scSheepDeath.getManageTags() == null || scSheepDeath.getManageTags().trim().isEmpty()) { return error("管理耳号不能为空"); } - - if (scSheepDeath.getDeathDate() == null) { - return error("死淘日期不能为空"); - } - - int result = scSheepDeathService.insertScSheepDeath(scSheepDeath); - if (result > 0) { - return success("新增成功"); - } else { - return error("新增失败"); - } - } catch (ServiceException e) { - logger.warn("新增羊只死淘记录业务异常: " + e.getMessage()); - return error(e.getMessage()); + return toAjax(scSheepDeathService.insertScSheepDeath(scSheepDeath)); } catch (Exception e) { - logger.error("新增羊只死淘记录失败", e); return error("新增失败: " + e.getMessage()); } } - /** - * 修改羊只死淘记录 - */ @PreAuthorize("@ss.hasPermi('sheep_death:death:edit')") @Log(title = "羊只死淘记录", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody ScSheepDeath scSheepDeath) { - try { - // 基础参数校验 - if (scSheepDeath == null) { - return error("请求参数不能为空"); - } - - if (scSheepDeath.getId() == null) { - return error("记录ID不能为空"); - } - - if (scSheepDeath.getManageTags() == null || scSheepDeath.getManageTags().trim().isEmpty()) { - return error("管理耳号不能为空"); - } - - if (scSheepDeath.getDeathDate() == null) { - return error("死淘日期不能为空"); - } - - int result = scSheepDeathService.updateScSheepDeath(scSheepDeath); - if (result > 0) { - return success("修改成功"); - } else { - return error("修改失败,记录可能不存在"); - } - } catch (ServiceException e) { - logger.warn("修改羊只死淘记录业务异常: " + e.getMessage()); - return error(e.getMessage()); - } catch (Exception e) { - logger.error("修改羊只死淘记录失败", e); - return error("修改失败: " + e.getMessage()); - } + return toAjax(scSheepDeathService.updateScSheepDeath(scSheepDeath)); } - /** - * 删除羊只死淘记录 - */ @PreAuthorize("@ss.hasPermi('sheep_death:death:remove')") @Log(title = "羊只死淘记录", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { - try { - if (ids == null || ids.length == 0) { - return error("删除的记录ID不能为空"); - } - - int result = scSheepDeathService.deleteScSheepDeathByIds(ids); - if (result > 0) { - return success("删除成功"); - } else { - return error("删除失败,记录可能不存在"); - } - } catch (ServiceException e) { - logger.warn("删除羊只死淘记录业务异常: " + e.getMessage()); - return error(e.getMessage()); - } catch (Exception e) { - logger.error("删除羊只死淘记录失败", e); - return error("删除失败: " + e.getMessage()); - } + return toAjax(scSheepDeathService.deleteScSheepDeathByIds(ids)); } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScWeanRecordController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScWeanRecordController.java index d454abf..8a8f693 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScWeanRecordController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScWeanRecordController.java @@ -3,17 +3,11 @@ package com.zhyc.module.produce.breed.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.zhyc.common.utils.StringUtils; import com.zhyc.module.produce.breed.domain.ScWeanRecord; 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,9 +18,6 @@ import com.zhyc.common.core.page.TableDataInfo; /** * 断奶记录Controller - * - * @author zhyc - * @date 2024-01-01 */ @RestController @RequestMapping("/Weaning/weaning_record") @@ -45,6 +36,16 @@ public class ScWeanRecordController extends BaseController { return getDataTable(list); } + /** + * 【新增】模糊查询耳号列表 (用于前端下拉框远程搜索) + */ + @PreAuthorize("@ss.hasPermi('Weaning:weaning_record:list')") + @GetMapping("/search_ear_numbers") + public AjaxResult searchEarNumbers(@RequestParam("query") String query) { + List list = scWeanRecordService.searchEarNumbers(query); + return success(list); + } + /** * 导出断奶记录列表 */ @@ -87,7 +88,6 @@ public class ScWeanRecordController extends BaseController { @Log(title = "断奶记录", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody ScWeanRecord scWeanRecord) { - // 验证耳号是否存在 if (scWeanRecord.getEarNumber() != null) { Long sheepId = scWeanRecordService.selectSheepIdByEarNumber(scWeanRecord.getEarNumber()); if (sheepId == null) { @@ -95,20 +95,10 @@ public class ScWeanRecordController extends BaseController { } scWeanRecord.setSheepId(sheepId); } - - // 验证必要字段 - if (scWeanRecord.getSheepId() == null) { - return error("羊只信息不能为空"); - } - if (scWeanRecord.getDatetime() == null) { - return error("断奶日期不能为空"); - } - if (scWeanRecord.getWeight() == null) { - return error("断奶重量不能为空"); - } - if (scWeanRecord.getStatus() == null) { - return error("是否留养不能为空"); - } + if (scWeanRecord.getSheepId() == null) return error("羊只信息不能为空"); + if (scWeanRecord.getDatetime() == null) return error("断奶日期不能为空"); + if (scWeanRecord.getWeight() == null) return error("断奶重量不能为空"); + if (scWeanRecord.getStatus() == null) return error("是否留养不能为空"); scWeanRecord.setCreateBy(getUsername()); return toAjax(scWeanRecordService.insertScWeanRecord(scWeanRecord)); @@ -121,32 +111,11 @@ public class ScWeanRecordController extends BaseController { @Log(title = "断奶记录", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody ScWeanRecord scWeanRecord) { - // 验证耳号是否存在 if (scWeanRecord.getEarNumber() != null) { Long sheepId = scWeanRecordService.selectSheepIdByEarNumber(scWeanRecord.getEarNumber()); - if (sheepId == null) { - return error("耳号不存在,请检查后重新输入"); - } + if (sheepId == null) return error("耳号不存在"); scWeanRecord.setSheepId(sheepId); } - - // 验证必要字段 - if (scWeanRecord.getId() == null) { - return error("记录ID不能为空"); - } - if (scWeanRecord.getSheepId() == null) { - return error("羊只信息不能为空"); - } - if (scWeanRecord.getDatetime() == null) { - return error("断奶日期不能为空"); - } - if (scWeanRecord.getWeight() == null) { - return error("断奶重量不能为空"); - } - if (scWeanRecord.getStatus() == null) { - return error("是否留养不能为空"); - } - return toAjax(scWeanRecordService.updateScWeanRecord(scWeanRecord)); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScDryMilk.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScDryMilk.java index 07ffe30..b093e2f 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScDryMilk.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScDryMilk.java @@ -1,6 +1,7 @@ package com.zhyc.module.produce.breed.domain; import java.util.Date; +import java.util.List; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Data; @@ -33,8 +34,8 @@ public class ScDryMilk extends BaseEntity @Excel(name = "干奶日期", width = 30, dateFormat = "yyyy-MM-dd") private Date datetime; - /** 是否使用乳头封闭剂 */ - @Excel(name = "是否使用乳头封闭剂") + /** 是否使用乳头封闭剂 (1:是 0:否) */ + @Excel(name = "是否使用乳头封闭剂", readConverterExp = "0=否,1=是") private Long status; /** 转入羊舍id */ @@ -49,12 +50,15 @@ public class ScDryMilk extends BaseEntity @Excel(name = "备注") private String comment; - // 以下为联表查询字段,不存储在sc_dry_milk表中 + // --- 联表查询字段 --- - /** 管理耳号 */ + /** 管理耳号 (单个) */ @Excel(name = "耳号") private String manageTags; + /** 多耳号查询列表 (核心修改:用于接收前端多选的数组) */ + private List manageTagsList; + /** 品种 */ @Excel(name = "品种") private String variety; @@ -66,6 +70,4 @@ public class ScDryMilk extends BaseEntity /** 事件类型 */ @Excel(name = "事件类型") private String eventType; - - } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScSheepDeath.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScSheepDeath.java index 52f04dd..91e6d91 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScSheepDeath.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScSheepDeath.java @@ -1,6 +1,7 @@ package com.zhyc.module.produce.breed.domain; import java.util.Date; +import java.util.List; import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -69,26 +70,34 @@ public class ScSheepDeath extends BaseEntity @Excel(name = "是否删除(0:未删除 1:已删除)") private Long isDelete; - // 以下字段仅用于前端显示,不存储到数据库 - /** 品种 */ + // --- 扩展字段 --- + + /** 品种 (查询显示用) */ + @Excel(name = "品种") private String variety; - /** 死亡时羊只类别 */ + /** 羊只类型 (原事假类型改为羊只类型查询) */ + @Excel(name = "羊只类型") private String sheepType; /** 性别 */ + @Excel(name = "性别", readConverterExp = "1=母,2=公") private Integer gender; /** 日龄 */ + @Excel(name = "日龄") private Long dayAge; /** 胎次 */ + @Excel(name = "胎次") private Integer parity; /** 羊舍 */ + @Excel(name = "羊舍") private String sheepfoldName; /** 繁育状态 */ + @Excel(name = "繁育状态") private String breedStatus; /** 死亡时产后天数 */ @@ -100,257 +109,124 @@ public class ScSheepDeath extends BaseEntity /** 死亡时怀孕天数 */ private Integer gestationDay; - public void setId(Long id) - { - this.id = id; - } + // 疾病名称 + private String diseaseTypeName; + private String diseaseSubtypeName; - public Long getId() - { - return id; - } + // --- 多选查询条件 --- - public void setSheepId(Long sheepId) - { - this.sheepId = sheepId; - } + /** 多选管理耳号列表 */ + private List manageTagsList; - public Long getSheepId() - { - return sheepId; - } + /** 多选羊只类型列表 */ + private List sheepTypeList; - public void setManageTags(String manageTags) - { - this.manageTags = manageTags; - } + /** 多选技术员列表 */ + private List technicianList; - public String getManageTags() - { - return manageTags; - } + /** 多选处理人列表 */ + private List handlerList; - public void setEventType(String eventType) - { - this.eventType = eventType; - } + /** 多选班组列表 */ + private List workGroupList; - public String getEventType() - { - return eventType; - } + // Getter & Setter + public void setId(Long id) { this.id = id; } + public Long getId() { return id; } - public void setDeathDate(Date deathDate) - { - this.deathDate = deathDate; - } + public void setSheepId(Long sheepId) { this.sheepId = sheepId; } + public Long getSheepId() { return sheepId; } - public Date getDeathDate() - { - return deathDate; - } + public void setManageTags(String manageTags) { this.manageTags = manageTags; } + public String getManageTags() { return manageTags; } - public void setDiseaseTypeId(Long diseaseTypeId) - { - this.diseaseTypeId = diseaseTypeId; - } + public void setEventType(String eventType) { this.eventType = eventType; } + public String getEventType() { return eventType; } - public Long getDiseaseTypeId() - { - return diseaseTypeId; - } + public void setDeathDate(Date deathDate) { this.deathDate = deathDate; } + public Date getDeathDate() { return deathDate; } - public void setDiseaseSubtypeId(Long diseaseSubtypeId) - { - this.diseaseSubtypeId = diseaseSubtypeId; - } + public void setDiseaseTypeId(Long diseaseTypeId) { this.diseaseTypeId = diseaseTypeId; } + public Long getDiseaseTypeId() { return diseaseTypeId; } - public Long getDiseaseSubtypeId() - { - return diseaseSubtypeId; - } + public void setDiseaseSubtypeId(Long diseaseSubtypeId) { this.diseaseSubtypeId = diseaseSubtypeId; } + public Long getDiseaseSubtypeId() { return diseaseSubtypeId; } - public void setDisposalDirection(String disposalDirection) - { - this.disposalDirection = disposalDirection; - } + public void setDisposalDirection(String disposalDirection) { this.disposalDirection = disposalDirection; } + public String getDisposalDirection() { return disposalDirection; } - public String getDisposalDirection() - { - return disposalDirection; - } + public void setTechnician(String technician) { this.technician = technician; } + public String getTechnician() { return technician; } - public void setTechnician(String technician) - { - this.technician = technician; - } + public void setHandler(String handler) { this.handler = handler; } + public String getHandler() { return handler; } - public String getTechnician() - { - return technician; - } + public void setWorkGroup(String workGroup) { this.workGroup = workGroup; } + public String getWorkGroup() { return workGroup; } - public void setHandler(String handler) - { - this.handler = handler; - } + public void setComment(String comment) { this.comment = comment; } + public String getComment() { return comment; } - public String getHandler() - { - return handler; - } + public void setIsDelete(Long isDelete) { this.isDelete = isDelete; } + public Long getIsDelete() { return isDelete; } - public void setWorkGroup(String workGroup) - { - this.workGroup = workGroup; - } + public void setVariety(String variety) { this.variety = variety; } + public String getVariety() { return variety; } - public String getWorkGroup() - { - return workGroup; - } + public void setSheepType(String sheepType) { this.sheepType = sheepType; } + public String getSheepType() { return sheepType; } - public void setComment(String comment) - { - this.comment = comment; - } + public void setGender(Integer gender) { this.gender = gender; } + public Integer getGender() { return gender; } - public String getComment() - { - return comment; - } + public void setDayAge(Long dayAge) { this.dayAge = dayAge; } + public Long getDayAge() { return dayAge; } - public void setIsDelete(Long isDelete) - { - this.isDelete = isDelete; - } + public void setParity(Integer parity) { this.parity = parity; } + public Integer getParity() { return parity; } - public Long getIsDelete() - { - return isDelete; - } + public void setSheepfoldName(String sheepfoldName) { this.sheepfoldName = sheepfoldName; } + public String getSheepfoldName() { return sheepfoldName; } - // 以下为仅用于显示的字段的getter/setter - public void setVariety(String variety) - { - this.variety = variety; - } + public void setBreedStatus(String breedStatus) { this.breedStatus = breedStatus; } + public String getBreedStatus() { return breedStatus; } - public String getVariety() - { - return variety; - } + public void setPostLambingDay(Integer postLambingDay) { this.postLambingDay = postLambingDay; } + public Integer getPostLambingDay() { return postLambingDay; } - public void setSheepType(String sheepType) - { - this.sheepType = sheepType; - } + public void setLactationDay(Integer lactationDay) { this.lactationDay = lactationDay; } + public Integer getLactationDay() { return lactationDay; } - public String getSheepType() - { - return sheepType; - } + public void setGestationDay(Integer gestationDay) { this.gestationDay = gestationDay; } + public Integer getGestationDay() { return gestationDay; } - public void setGender(Integer gender) - { - this.gender = gender; - } + public String getDiseaseTypeName() { return diseaseTypeName; } + public void setDiseaseTypeName(String diseaseTypeName) { this.diseaseTypeName = diseaseTypeName; } - public Integer getGender() - { - return gender; - } + public String getDiseaseSubtypeName() { return diseaseSubtypeName; } + public void setDiseaseSubtypeName(String diseaseSubtypeName) { this.diseaseSubtypeName = diseaseSubtypeName; } - public void setDayAge(Long dayAge) - { - this.dayAge = dayAge; - } + public List getManageTagsList() { return manageTagsList; } + public void setManageTagsList(List manageTagsList) { this.manageTagsList = manageTagsList; } - public Long getDayAge() - { - return dayAge; - } + public List getSheepTypeList() { return sheepTypeList; } + public void setSheepTypeList(List sheepTypeList) { this.sheepTypeList = sheepTypeList; } - public void setParity(Integer parity) - { - this.parity = parity; - } + public List getTechnicianList() { return technicianList; } + public void setTechnicianList(List technicianList) { this.technicianList = technicianList; } - public Integer getParity() - { - return parity; - } + public List getHandlerList() { return handlerList; } + public void setHandlerList(List handlerList) { this.handlerList = handlerList; } - public void setSheepfoldName(String sheepfoldName) - { - this.sheepfoldName = sheepfoldName; - } - - public String getSheepfoldName() - { - return sheepfoldName; - } - - public void setBreedStatus(String breedStatus) - { - this.breedStatus = breedStatus; - } - - public String getBreedStatus() - { - return breedStatus; - } - - public void setPostLambingDay(Integer postLambingDay) - { - this.postLambingDay = postLambingDay; - } - - public Integer getPostLambingDay() - { - return postLambingDay; - } - - public void setLactationDay(Integer lactationDay) - { - this.lactationDay = lactationDay; - } - - public Integer getLactationDay() - { - return lactationDay; - } - - public void setGestationDay(Integer gestationDay) - { - this.gestationDay = gestationDay; - } - - public Integer getGestationDay() - { - return gestationDay; - } + public List getWorkGroupList() { return workGroupList; } + public void setWorkGroupList(List workGroupList) { this.workGroupList = workGroupList; } @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) .append("id", getId()) - .append("sheepId", getSheepId()) .append("manageTags", getManageTags()) - .append("eventType", getEventType()) .append("deathDate", getDeathDate()) - .append("diseaseTypeId", getDiseaseTypeId()) - .append("diseaseSubtypeId", getDiseaseSubtypeId()) - .append("disposalDirection", getDisposalDirection()) - .append("technician", getTechnician()) - .append("handler", getHandler()) - .append("workGroup", getWorkGroup()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("comment", getComment()) - .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/domain/ScWeanRecord.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScWeanRecord.java index b0e4dcb..f53ba46 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScWeanRecord.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScWeanRecord.java @@ -2,6 +2,7 @@ package com.zhyc.module.produce.breed.domain; import java.math.BigDecimal; import java.util.Date; +import java.util.List; import com.fasterxml.jackson.annotation.JsonFormat; import com.zhyc.common.annotation.Excel; import com.zhyc.common.core.domain.BaseEntity; @@ -11,9 +12,6 @@ import lombok.NoArgsConstructor; /** * 断奶记录对象 sc_wean_record - * - * @author zhyc - * @date 2024-01-01 */ @Data @NoArgsConstructor @@ -53,46 +51,46 @@ public class ScWeanRecord extends BaseEntity { @Excel(name = "电子耳号") private String electronicTags; - // 关联查询字段 - /** 耳号 */ + // --- 新增查询字段 --- + + /** 多耳号查询列表 */ + private List allEarNumbers; + + /** 是否在群 (1是 0否) */ + private String isInHerd; + + /** 羊只类别 (对应 sheep_file 的 breed 字段) */ + private String sheepCategory; + + // --- 关联查询显示字段 --- + @Excel(name = "耳号") private String earNumber; - /** 品种 */ @Excel(name = "品种") private String breed; - /** 事件类型 */ @Excel(name = "事件类型") private String eventType; - /** 性别 */ @Excel(name = "性别") private String gender; - /** 父号 */ @Excel(name = "父号") private String fatherNumber; - /** 母号 */ @Excel(name = "母号") private String motherNumber; - /** 月龄 */ @Excel(name = "月龄") private Integer monthAge; - /** 出生重量 */ @Excel(name = "出生重量") private BigDecimal birthWeight; - /** 羊舍 */ @Excel(name = "羊舍") private String sheepPen; - /** 繁育状态 */ @Excel(name = "繁育状态") private String breedingStatus; - - } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScDryMilkMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScDryMilkMapper.java index 742dbe7..97440c0 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScDryMilkMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScDryMilkMapper.java @@ -2,70 +2,66 @@ package com.zhyc.module.produce.breed.mapper; import java.util.List; import com.zhyc.module.produce.breed.domain.ScDryMilk; -import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 干奶记录Mapper接口 - * - * @author ruoyi + * * @author ruoyi * @date 2025-07-15 */ -@Mapper public interface ScDryMilkMapper { /** * 查询干奶记录 - * - * @param id 干奶记录主键 + * * @param id 干奶记录主键 * @return 干奶记录 */ public ScDryMilk selectScDryMilkById(Long id); /** * 查询干奶记录列表 - * - * @param scDryMilk 干奶记录 + * * @param scDryMilk 干奶记录 * @return 干奶记录集合 */ public List selectScDryMilkList(ScDryMilk scDryMilk); - /** - * 根据耳号查询羊只ID - * - * @param manageTags 管理耳号 - * @return 羊只ID - */ - public Long selectSheepIdByManageTags(String manageTags); - /** * 新增干奶记录 - * - * @param scDryMilk 干奶记录 + * * @param scDryMilk 干奶记录 * @return 结果 */ public int insertScDryMilk(ScDryMilk scDryMilk); /** * 修改干奶记录 - * - * @param scDryMilk 干奶记录 + * * @param scDryMilk 干奶记录 * @return 结果 */ public int updateScDryMilk(ScDryMilk scDryMilk); /** * 删除干奶记录 - * - * @param id 干奶记录主键 + * * @param id 干奶记录主键 * @return 结果 */ public int deleteScDryMilkById(Long id); /** * 批量删除干奶记录 - * - * @param ids 需要删除的数据主键集合 + * * @param ids 需要删除的数据主键集合 * @return 结果 */ - public int deleteScDryMilkByIds(Long[] ids); + public int deleteScDryMilkByIds(String[] ids); + + /** + * 根据耳号查询羊只ID + */ + public Long selectSheepIdByManageTags(String manageTags); + + /** + * 远程搜索耳号列表 (新增) + * @param query 搜索关键字 + * @return 耳号列表 + */ + public List selectSheepEarNumberList(@Param("query") String query); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScSheepDeathMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScSheepDeathMapper.java index 853ab39..b0e1a9d 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScSheepDeathMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScSheepDeathMapper.java @@ -2,8 +2,8 @@ package com.zhyc.module.produce.breed.mapper; import java.util.List; import java.util.Map; -import org.apache.ibatis.annotations.Param; import com.zhyc.module.produce.breed.domain.ScSheepDeath; +import org.apache.ibatis.annotations.Param; /** * 羊只死淘记录Mapper接口 @@ -29,14 +29,6 @@ public interface ScSheepDeathMapper */ public List selectScSheepDeathList(ScSheepDeath scSheepDeath); - /** - * 根据管理耳号查询sheep_file视图信息 - * - * @param manageTags 管理耳号 - * @return 羊只信息 - */ - public Map selectSheepFileByManageTags(String manageTags); - /** * 新增羊只死淘记录 * @@ -70,20 +62,27 @@ public interface ScSheepDeathMapper public int deleteScSheepDeathByIds(Long[] ids); /** - * 更新羊只繁育状态 - * - * @param sheepId 羊只ID - * @param status 繁育状态 - * @return 更新结果 + * 根据管理耳号查询sheep_file视图信息 */ - public int updateSheepFileStatus(@Param("sheepId") Long sheepId, @Param("status") String status); + public Map selectSheepFileByManageTags(@Param("manageTags") String manageTags); /** - * 新增:更新羊只在群状态 - * - * @param sheepId 羊只ID - * @param status 在群状态(1-在群,2-不在群) - * @return 更新结果 + * 更新羊只在群状态 */ public int updateSheepStatus(@Param("sheepId") Long sheepId, @Param("status") String status); + + /** + * 远程搜索:管理耳号 + */ + public List selectDistinctManageTags(@Param("query") String query); + + /** + * 远程搜索:技术员 + */ + public List selectDistinctTechnician(@Param("query") String query); + + /** + * 远程搜索:处理人 + */ + public List selectDistinctHandler(@Param("query") String query); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScWeanRecordMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScWeanRecordMapper.java index cb74588..3958729 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScWeanRecordMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScWeanRecordMapper.java @@ -2,77 +2,75 @@ package com.zhyc.module.produce.breed.mapper; import java.util.List; import com.zhyc.module.produce.breed.domain.ScWeanRecord; -import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 断奶记录Mapper接口 - * - * @author zhyc + * * @author zhyc * @date 2024-01-01 */ -@Mapper -public interface ScWeanRecordMapper { +public interface ScWeanRecordMapper +{ /** * 查询断奶记录 - * - * @param id 断奶记录主键 + * * @param id 断奶记录主键 * @return 断奶记录 */ public ScWeanRecord selectScWeanRecordById(Long id); /** * 查询断奶记录列表 - * - * @param scWeanRecord 断奶记录 + * * @param scWeanRecord 断奶记录 * @return 断奶记录集合 */ public List selectScWeanRecordList(ScWeanRecord scWeanRecord); /** * 新增断奶记录 - * - * @param scWeanRecord 断奶记录 + * * @param scWeanRecord 断奶记录 * @return 结果 */ public int insertScWeanRecord(ScWeanRecord scWeanRecord); /** * 修改断奶记录 - * - * @param scWeanRecord 断奶记录 + * * @param scWeanRecord 断奶记录 * @return 结果 */ public int updateScWeanRecord(ScWeanRecord scWeanRecord); /** * 删除断奶记录 - * - * @param id 断奶记录主键 + * * @param id 断奶记录主键 * @return 结果 */ public int deleteScWeanRecordById(Long id); /** * 批量删除断奶记录 - * - * @param ids 需要删除的数据主键集合 + * * @param ids 需要删除的数据主键集合 * @return 结果 */ public int deleteScWeanRecordByIds(Long[] ids); /** * 根据耳号查询羊只ID - * * @param earNumber 耳号 * @return 羊只ID */ public Long selectSheepIdByEarNumber(String earNumber); /** - * 根据耳号更新bas_sheep表中的断奶信息 - * - * @param scWeanRecord 断奶记录 + * 更新基础羊只表的断奶信息 (对应XML中的updateBasSheepWeaningInfo) + * @param scWeanRecord 断奶信息 * @return 结果 */ public int updateBasSheepWeaningInfo(ScWeanRecord scWeanRecord); + + /** + * 【新增】模糊查询耳号列表 (用于前端远程搜索) + * @param query 查询关键字 + * @return 耳号列表 + */ + public List searchEarNumbers(@Param("query") String query); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScDryMilkService.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScDryMilkService.java index ad90b57..6c05394 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScDryMilkService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScDryMilkService.java @@ -5,59 +5,62 @@ import com.zhyc.module.produce.breed.domain.ScDryMilk; /** * 干奶记录Service接口 - * - * @author ruoyi + * * @author ruoyi * @date 2025-07-15 */ -public interface IScDryMilkService +public interface IScDryMilkService { /** * 查询干奶记录 - * - * @param id 干奶记录主键 + * * @param id 干奶记录主键 * @return 干奶记录 */ public ScDryMilk selectScDryMilkById(Long id); /** * 查询干奶记录列表 - * - * @param scDryMilk 干奶记录 + * * @param scDryMilk 干奶记录 * @return 干奶记录集合 */ public List selectScDryMilkList(ScDryMilk scDryMilk); - Long selectSheepIdByManageTags(String manageTags); - /** * 新增干奶记录 - * - * @param scDryMilk 干奶记录 + * * @param scDryMilk 干奶记录 * @return 结果 */ public int insertScDryMilk(ScDryMilk scDryMilk); /** * 修改干奶记录 - * - * @param scDryMilk 干奶记录 + * * @param scDryMilk 干奶记录 * @return 结果 */ public int updateScDryMilk(ScDryMilk scDryMilk); /** * 批量删除干奶记录 - * - * @param ids 需要删除的干奶记录主键集合 + * * @param ids 需要删除的干奶记录主键集合 * @return 结果 */ public int deleteScDryMilkByIds(Long[] ids); /** * 删除干奶记录信息 - * - * @param id 干奶记录主键 + * * @param id 干奶记录主键 * @return 结果 */ public int deleteScDryMilkById(Long id); -} + + /** + * 根据耳号查询羊只ID + */ + public Long selectSheepIdByManageTags(String manageTags); + + /** + * 远程搜索耳号列表 (新增方法) + * @param query 搜索关键字 + * @return 耳号列表 + */ + public List selectSheepEarNumberList(String query); +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScSheepDeathService.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScSheepDeathService.java index e1100d5..b0f6bfb 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScSheepDeathService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScSheepDeathService.java @@ -28,14 +28,6 @@ public interface IScSheepDeathService */ public List selectScSheepDeathList(ScSheepDeath scSheepDeath); - /** - * 根据管理耳号查询sheep_file视图信息 - * - * @param manageTags 管理耳号 - * @return 羊只信息 - */ - public Map selectSheepFileByManageTags(String manageTags); - /** * 新增羊只死淘记录 * @@ -67,4 +59,27 @@ public interface IScSheepDeathService * @return 结果 */ public int deleteScSheepDeathById(Long id); + + /** + * 根据管理耳号查询sheep_file视图信息 + * + * @param manageTags 管理耳号 + * @return 羊只信息 + */ + public Map selectSheepFileByManageTags(String manageTags); + + /** + * 远程搜索:管理耳号 + */ + public List selectDistinctManageTags(String query); + + /** + * 远程搜索:技术员 + */ + public List selectDistinctTechnician(String query); + + /** + * 远程搜索:处理人 + */ + public List selectDistinctHandler(String query); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScWeanRecordService.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScWeanRecordService.java index 9f49b44..d94bd76 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScWeanRecordService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScWeanRecordService.java @@ -1,69 +1,68 @@ package com.zhyc.module.produce.breed.service; import java.util.List; - import com.zhyc.module.produce.breed.domain.ScWeanRecord; /** * 断奶记录Service接口 - * - * @author ruoyi - * @date 2025-07-13 + * * @author zhyc + * @date 2024-01-01 */ -public interface IScWeanRecordService { +public interface IScWeanRecordService +{ /** * 查询断奶记录 - * - * @param id 断奶记录主键 + * * @param id 断奶记录主键 * @return 断奶记录 */ public ScWeanRecord selectScWeanRecordById(Long id); /** * 查询断奶记录列表 - * - * @param scWeanRecord 断奶记录 + * * @param scWeanRecord 断奶记录 * @return 断奶记录集合 */ public List selectScWeanRecordList(ScWeanRecord scWeanRecord); /** * 新增断奶记录 - * - * @param scWeanRecord 断奶记录 + * * @param scWeanRecord 断奶记录 * @return 结果 */ public int insertScWeanRecord(ScWeanRecord scWeanRecord); /** * 修改断奶记录 - * - * @param scWeanRecord 断奶记录 + * * @param scWeanRecord 断奶记录 * @return 结果 */ public int updateScWeanRecord(ScWeanRecord scWeanRecord); /** * 批量删除断奶记录 - * - * @param ids 需要删除的断奶记录主键集合 + * * @param ids 需要删除的断奶记录主键集合 * @return 结果 */ public int deleteScWeanRecordByIds(Long[] ids); /** * 删除断奶记录信息 - * - * @param id 断奶记录主键 + * * @param id 断奶记录主键 * @return 结果 */ public int deleteScWeanRecordById(Long id); /** * 根据耳号查询羊只ID - * * @param earNumber 耳号 * @return 羊只ID */ public Long selectSheepIdByEarNumber(String earNumber); + + /** + * 【新增】模糊查询耳号列表 + * @param query 查询关键字 + * @return 耳号列表 + */ + public List searchEarNumbers(String query); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScDryMilkServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScDryMilkServiceImpl.java index 3ba8322..548fc78 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScDryMilkServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScDryMilkServiceImpl.java @@ -1,20 +1,16 @@ package com.zhyc.module.produce.breed.service.impl; import java.util.List; -import java.util.Date; +import com.zhyc.common.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.zhyc.module.produce.breed.mapper.ScDryMilkMapper; import com.zhyc.module.produce.breed.domain.ScDryMilk; import com.zhyc.module.produce.breed.service.IScDryMilkService; -import com.zhyc.common.utils.StringUtils; -import com.zhyc.common.utils.DateUtils; -import com.zhyc.common.exception.ServiceException; /** * 干奶记录Service业务层处理 - * - * @author ruoyi + * * @author ruoyi * @date 2025-07-15 */ @Service @@ -25,8 +21,7 @@ public class ScDryMilkServiceImpl implements IScDryMilkService /** * 查询干奶记录 - * - * @param id 干奶记录主键 + * * @param id 干奶记录主键 * @return 干奶记录 */ @Override @@ -37,8 +32,7 @@ public class ScDryMilkServiceImpl implements IScDryMilkService /** * 查询干奶记录列表 - * - * @param scDryMilk 干奶记录 + * * @param scDryMilk 干奶记录 * @return 干奶记录 */ @Override @@ -47,90 +41,49 @@ public class ScDryMilkServiceImpl implements IScDryMilkService return scDryMilkMapper.selectScDryMilkList(scDryMilk); } - /** - * 根据耳号查询羊只ID - * - * @param manageTags 管理耳号 - * @return 羊只ID - */ - @Override - public Long selectSheepIdByManageTags(String manageTags) - { - return scDryMilkMapper.selectSheepIdByManageTags(manageTags); - } - /** * 新增干奶记录 - * - * @param scDryMilk 干奶记录 + * * @param scDryMilk 干奶记录 * @return 结果 */ @Override public int insertScDryMilk(ScDryMilk scDryMilk) { - // 如果传入的是耳号,需要转换为羊只ID - if (StringUtils.isNotEmpty(scDryMilk.getManageTags()) && StringUtils.isEmpty(scDryMilk.getSheepId())) - { - Long sheepId = scDryMilkMapper.selectSheepIdByManageTags(scDryMilk.getManageTags()); - if (sheepId == null) - { - throw new ServiceException("未找到对应耳号的羊只信息"); - } - scDryMilk.setSheepId(String.valueOf(sheepId)); - } - - // 自动设置创建时间(精确到分钟) scDryMilk.setCreateTime(DateUtils.getNowDate()); - // 如果有获取当前用户的方法,可以设置创建人 - // scDryMilk.setCreateBy(SecurityUtils.getUsername()); - return scDryMilkMapper.insertScDryMilk(scDryMilk); } /** * 修改干奶记录 - * - * @param scDryMilk 干奶记录 + * * @param scDryMilk 干奶记录 * @return 结果 */ @Override public int updateScDryMilk(ScDryMilk scDryMilk) { - // 如果传入的是耳号,需要转换为羊只ID - if (StringUtils.isNotEmpty(scDryMilk.getManageTags()) && StringUtils.isEmpty(scDryMilk.getSheepId())) - { - Long sheepId = scDryMilkMapper.selectSheepIdByManageTags(scDryMilk.getManageTags()); - if (sheepId == null) - { - throw new ServiceException("未找到对应耳号的羊只信息"); - } - scDryMilk.setSheepId(String.valueOf(sheepId)); - } - - // 设置更新时间 - scDryMilk.setUpdateTime(DateUtils.getNowDate()); - // 如果有获取当前用户的方法,可以设置更新人 - // scDryMilk.setUpdateBy(SecurityUtils.getUsername()); - return scDryMilkMapper.updateScDryMilk(scDryMilk); } /** * 批量删除干奶记录 - * - * @param ids 需要删除的干奶记录主键 + * * @param ids 需要删除的干奶记录主键 * @return 结果 */ @Override public int deleteScDryMilkByIds(Long[] ids) { - return scDryMilkMapper.deleteScDryMilkByIds(ids); + // 假设ids是Long数组,需要转为String[]传给Mapper,或者修改Mapper接收Long[] + // 这里根据Mapper XML通常接收String[]或Array的习惯,做个转换 + String[] stringIds = new String[ids.length]; + for(int i=0;i selectSheepEarNumberList(String query) { + return scDryMilkMapper.selectSheepEarNumberList(query); + } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScSheepDeathServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScSheepDeathServiceImpl.java index 029db5a..9cfd039 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScSheepDeathServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScSheepDeathServiceImpl.java @@ -3,6 +3,7 @@ package com.zhyc.module.produce.breed.service.impl; import java.util.List; import java.util.Map; import com.zhyc.common.utils.DateUtils; +import com.zhyc.common.utils.bean.BeanUtils; import com.zhyc.module.biosafety.domain.Diagnosis; import com.zhyc.module.biosafety.domain.Treatment; import com.zhyc.module.biosafety.mapper.DiagnosisMapper; @@ -31,134 +32,77 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService @Autowired private TreatmentServiceImpl treatmentService; - - - - /** - * 查询羊只死淘记录 - * - * @param id 羊只死淘记录主键 - * @return 羊只死淘记录 - */ @Override public ScSheepDeath selectScSheepDeathById(Long id) { - ScSheepDeath scSheepDeath = scSheepDeathMapper.selectScSheepDeathById(id); - // 查询时也需要填充显示字段 - if (scSheepDeath != null && scSheepDeath.getManageTags() != null) { - Map sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags()); - if (sheepInfo != null) { - scSheepDeath.setVariety(sheepInfo.get("variety") != null ? sheepInfo.get("variety").toString() : null); - scSheepDeath.setSheepType(sheepInfo.get("sheepType") != null ? sheepInfo.get("sheepType").toString() : null); - scSheepDeath.setGender(sheepInfo.get("gender") != null ? Integer.valueOf(sheepInfo.get("gender").toString()) : null); - scSheepDeath.setDayAge(sheepInfo.get("dayAge") != null ? Long.valueOf(sheepInfo.get("dayAge").toString()) : null); - scSheepDeath.setParity(sheepInfo.get("parity") != null ? Integer.valueOf(sheepInfo.get("parity").toString()) : null); - scSheepDeath.setSheepfoldName(sheepInfo.get("sheepfoldName") != null ? sheepInfo.get("sheepfoldName").toString() : null); - scSheepDeath.setBreedStatus(sheepInfo.get("breedStatus") != null ? sheepInfo.get("breedStatus").toString() : null); - scSheepDeath.setPostLambingDay(sheepInfo.get("postLambingDay") != null ? Integer.valueOf(sheepInfo.get("postLambingDay").toString()) : null); - scSheepDeath.setLactationDay(sheepInfo.get("lactationDay") != null ? Integer.valueOf(sheepInfo.get("lactationDay").toString()) : null); - scSheepDeath.setGestationDay(sheepInfo.get("gestationDay") != null ? Integer.valueOf(sheepInfo.get("gestationDay").toString()) : null); - } - } - return scSheepDeath; + return scSheepDeathMapper.selectScSheepDeathById(id); } - /** - * 查询羊只死淘记录列表 - * - * @param scSheepDeath 羊只死淘记录 - * @return 羊只死淘记录 - */ @Override public List selectScSheepDeathList(ScSheepDeath scSheepDeath) { - List list = scSheepDeathMapper.selectScSheepDeathList(scSheepDeath); - // 为列表中的每条记录填充显示字段 - for (ScSheepDeath death : list) { - if (death.getManageTags() != null) { - Map sheepInfo = selectSheepFileByManageTags(death.getManageTags()); - if (sheepInfo != null) { - death.setVariety(sheepInfo.get("variety") != null ? sheepInfo.get("variety").toString() : null); - death.setSheepType(sheepInfo.get("sheepType") != null ? sheepInfo.get("sheepType").toString() : null); - death.setGender(sheepInfo.get("gender") != null ? Integer.valueOf(sheepInfo.get("gender").toString()) : null); - death.setDayAge(sheepInfo.get("dayAge") != null ? Long.valueOf(sheepInfo.get("dayAge").toString()) : null); - death.setParity(sheepInfo.get("parity") != null ? Integer.valueOf(sheepInfo.get("parity").toString()) : null); - death.setSheepfoldName(sheepInfo.get("sheepfoldName") != null ? sheepInfo.get("sheepfoldName").toString() : null); - death.setBreedStatus(sheepInfo.get("breedStatus") != null ? sheepInfo.get("breedStatus").toString() : null); - death.setPostLambingDay(sheepInfo.get("postLambingDay") != null ? Integer.valueOf(sheepInfo.get("postLambingDay").toString()) : null); - death.setLactationDay(sheepInfo.get("lactationDay") != null ? Integer.valueOf(sheepInfo.get("lactationDay").toString()) : null); - death.setGestationDay(sheepInfo.get("gestationDay") != null ? Integer.valueOf(sheepInfo.get("gestationDay").toString()) : null); - } - } - } - return list; + return scSheepDeathMapper.selectScSheepDeathList(scSheepDeath); } - /** - * 根据管理耳号查询sheep_file视图信息 - * - * @param manageTags 管理耳号 - * @return 羊只信息 - */ @Override public Map selectSheepFileByManageTags(String manageTags) { return scSheepDeathMapper.selectSheepFileByManageTags(manageTags); } - /** - * 新增羊只死淘记录 - * - * @param scSheepDeath 羊只死淘记录 - * @return 结果 - */ @Override @Transactional public int insertScSheepDeath(ScSheepDeath scSheepDeath) { - // 设置事件类型默认为"死亡" - if (scSheepDeath.getEventType() == null || scSheepDeath.getEventType().isEmpty()) { - scSheepDeath.setEventType("死亡"); + String manageTagsInput = scSheepDeath.getManageTags(); + if (manageTagsInput == null || manageTagsInput.trim().isEmpty()) { + return 0; } - // 如果有管理耳号,查询并设置羊只ID - if (scSheepDeath.getManageTags() != null && !scSheepDeath.getManageTags().isEmpty()) { - Map sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags()); + // 支持空格、逗号分隔 + String[] tags = manageTagsInput.split("[\\s,,]+"); + int successCount = 0; + + for (String tag : tags) { + if (tag == null || tag.trim().isEmpty()) { + continue; + } + + ScSheepDeath newRecord = new ScSheepDeath(); + BeanUtils.copyProperties(scSheepDeath, newRecord); + newRecord.setManageTags(tag.trim()); + newRecord.setId(null); + + if (newRecord.getEventType() == null || newRecord.getEventType().isEmpty()) { + newRecord.setEventType("死亡"); + } + + Map sheepInfo = selectSheepFileByManageTags(newRecord.getManageTags()); if (sheepInfo != null) { Long sheepId = sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null; - scSheepDeath.setSheepId(sheepId); + newRecord.setSheepId(sheepId); - // 插入死淘记录后,同时更新羊只在群状态为"不在群"(状态ID为2) if (sheepId != null) { scSheepDeathMapper.updateSheepStatus(sheepId, "2"); + treatmentService.updateTreatmentStatus(sheepId); } } + + newRecord.setCreateTime(DateUtils.getNowDate()); + successCount += scSheepDeathMapper.insertScSheepDeath(newRecord); } - - treatmentService.updateTreatmentStatus(scSheepDeath.getSheepId()); - - scSheepDeath.setCreateTime(DateUtils.getNowDate()); - - return scSheepDeathMapper.insertScSheepDeath(scSheepDeath); + return successCount; } - /** - * 修改羊只死淘记录 - * - * @param scSheepDeath 羊只死淘记录 - * @return 结果 - */ @Override public int updateScSheepDeath(ScSheepDeath scSheepDeath) { - // 如果管理耳号发生变化,重新查询并设置羊只ID if (scSheepDeath.getManageTags() != null && !scSheepDeath.getManageTags().isEmpty()) { Map sheepInfo = selectSheepFileByManageTags(scSheepDeath.getManageTags()); if (sheepInfo != null) { Long sheepId = sheepInfo.get("sheepId") != null ? Long.valueOf(sheepInfo.get("sheepId").toString()) : null; scSheepDeath.setSheepId(sheepId); - // 修改死淘记录时,同时更新羊只在群状态为"不在群"(状态ID为2) if (sheepId != null) { scSheepDeathMapper.updateSheepStatus(sheepId, "2"); } @@ -168,43 +112,41 @@ public class ScSheepDeathServiceImpl implements IScSheepDeathService return scSheepDeathMapper.updateScSheepDeath(scSheepDeath); } - /** - * 批量删除羊只死淘记录 - * - * @param ids 需要删除的羊只死淘记录主键 - * @return 结果 - */ @Override public int deleteScSheepDeathByIds(Long[] ids) { - // 删除死淘记录前,将对应羊只在群状态改回"在群" for (Long id : ids) { ScSheepDeath scSheepDeath = scSheepDeathMapper.selectScSheepDeathById(id); if (scSheepDeath != null && scSheepDeath.getSheepId() != null) { - // 恢复羊只在群状态为"在群"(状态ID为1) scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1"); } } - return scSheepDeathMapper.deleteScSheepDeathByIds(ids); } - /** - * 删除羊只死淘记录信息 - * - * @param id 羊只死淘记录主键 - * @return 结果 - */ @Override public int deleteScSheepDeathById(Long id) { - // 删除死淘记录前,将对应羊只在群状态改回"在群" ScSheepDeath scSheepDeath = scSheepDeathMapper.selectScSheepDeathById(id); if (scSheepDeath != null && scSheepDeath.getSheepId() != null) { - // 恢复羊只在群状态为"在群"(状态ID为1) scSheepDeathMapper.updateSheepStatus(scSheepDeath.getSheepId(), "1"); } - return scSheepDeathMapper.deleteScSheepDeathById(id); } + + // --- 远程搜索实现 --- + @Override + public List selectDistinctManageTags(String query) { + return scSheepDeathMapper.selectDistinctManageTags(query); + } + + @Override + public List selectDistinctTechnician(String query) { + return scSheepDeathMapper.selectDistinctTechnician(query); + } + + @Override + public List selectDistinctHandler(String query) { + return scSheepDeathMapper.selectDistinctHandler(query); + } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScWeanRecordServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScWeanRecordServiceImpl.java index 9efcaff..cb3e6ee 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScWeanRecordServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScWeanRecordServiceImpl.java @@ -2,133 +2,123 @@ package com.zhyc.module.produce.breed.service.impl; import java.util.List; import com.zhyc.common.utils.DateUtils; -import com.zhyc.module.produce.breed.domain.ScWeanRecord; -import com.zhyc.module.produce.breed.mapper.ScWeanRecordMapper; -import com.zhyc.module.produce.breed.service.IScWeanRecordService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.zhyc.module.produce.breed.mapper.ScWeanRecordMapper; +import com.zhyc.module.produce.breed.domain.ScWeanRecord; +import com.zhyc.module.produce.breed.service.IScWeanRecordService; import org.springframework.transaction.annotation.Transactional; /** * 断奶记录Service业务层处理 - * - * @author ruoyi - * @date 2025-07-13 + * * @author zhyc + * @date 2024-01-01 */ @Service -public class ScWeanRecordServiceImpl implements IScWeanRecordService { +public class ScWeanRecordServiceImpl implements IScWeanRecordService +{ @Autowired private ScWeanRecordMapper scWeanRecordMapper; /** * 查询断奶记录 - * - * @param id 断奶记录主键 + * * @param id 断奶记录主键 * @return 断奶记录 */ @Override - public ScWeanRecord selectScWeanRecordById(Long id) { + public ScWeanRecord selectScWeanRecordById(Long id) + { return scWeanRecordMapper.selectScWeanRecordById(id); } /** * 查询断奶记录列表 - * - * @param scWeanRecord 断奶记录 + * * @param scWeanRecord 断奶记录 * @return 断奶记录 */ @Override - public List selectScWeanRecordList(ScWeanRecord scWeanRecord) { + public List selectScWeanRecordList(ScWeanRecord scWeanRecord) + { return scWeanRecordMapper.selectScWeanRecordList(scWeanRecord); } /** * 新增断奶记录 - * - * @param scWeanRecord 断奶记录 + * * @param scWeanRecord 断奶记录 * @return 结果 */ @Override @Transactional - public int insertScWeanRecord(ScWeanRecord scWeanRecord) { - // 如果前端传递的是耳号,需要先获取羊只ID - if (scWeanRecord.getEarNumber() != null && scWeanRecord.getSheepId() == null) { - Long sheepId = scWeanRecordMapper.selectSheepIdByEarNumber(scWeanRecord.getEarNumber()); - if (sheepId != null) { - scWeanRecord.setSheepId(sheepId); - } - } + public int insertScWeanRecord(ScWeanRecord scWeanRecord) + { scWeanRecord.setCreateTime(DateUtils.getNowDate()); + // 1. 插入断奶记录 + int rows = scWeanRecordMapper.insertScWeanRecord(scWeanRecord); - // 插入断奶记录 - int result = scWeanRecordMapper.insertScWeanRecord(scWeanRecord); - - // 同步更新bas_sheep表中的断奶信息 - if (result > 0 && scWeanRecord.getEarNumber() != null) { + // 2. 同步更新羊只档案中的断奶状态(断奶日期、断奶重、电子耳号等) + // 确保 scWeanRecord 中包含 earNumber (Controller中add方法校验过) + if (rows > 0 && scWeanRecord.getEarNumber() != null) { scWeanRecordMapper.updateBasSheepWeaningInfo(scWeanRecord); } - - return result; + return rows; } /** * 修改断奶记录 - * - * @param scWeanRecord 断奶记录 + * * @param scWeanRecord 断奶记录 * @return 结果 */ @Override @Transactional - public int updateScWeanRecord(ScWeanRecord scWeanRecord) { - // 如果前端传递的是耳号,需要先获取羊只ID - if (scWeanRecord.getEarNumber() != null && scWeanRecord.getSheepId() == null) { - Long sheepId = scWeanRecordMapper.selectSheepIdByEarNumber(scWeanRecord.getEarNumber()); - if (sheepId != null) { - scWeanRecord.setSheepId(sheepId); - } - } + public int updateScWeanRecord(ScWeanRecord scWeanRecord) + { + // 1. 更新断奶记录 + int rows = scWeanRecordMapper.updateScWeanRecord(scWeanRecord); - // 更新断奶记录 - int result = scWeanRecordMapper.updateScWeanRecord(scWeanRecord); - - // 同步更新bas_sheep表中的断奶信息 - if (result > 0 && scWeanRecord.getEarNumber() != null) { + // 2. 同步更新羊只档案信息 + if (rows > 0 && scWeanRecord.getEarNumber() != null) { scWeanRecordMapper.updateBasSheepWeaningInfo(scWeanRecord); } - - return result; + return rows; } /** * 批量删除断奶记录 - * - * @param ids 需要删除的断奶记录主键 + * * @param ids 需要删除的断奶记录主键 * @return 结果 */ @Override - public int deleteScWeanRecordByIds(Long[] ids) { + public int deleteScWeanRecordByIds(Long[] ids) + { return scWeanRecordMapper.deleteScWeanRecordByIds(ids); } /** * 删除断奶记录信息 - * - * @param id 断奶记录主键 + * * @param id 断奶记录主键 * @return 结果 */ @Override - public int deleteScWeanRecordById(Long id) { + public int deleteScWeanRecordById(Long id) + { return scWeanRecordMapper.deleteScWeanRecordById(id); } /** * 根据耳号查询羊只ID - * - * @param earNumber 耳号 - * @return 羊只ID */ @Override public Long selectSheepIdByEarNumber(String earNumber) { return scWeanRecordMapper.selectSheepIdByEarNumber(earNumber); } + + /** + * 【新增】模糊查询耳号列表 (用于前端远程搜索) + * @param query 查询关键字 + * @return 耳号列表 + */ + @Override + public List searchEarNumbers(String query) { + return scWeanRecordMapper.searchEarNumbers(query); + } } \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/produce/breed/ScDryMilkMapper.xml b/zhyc-module/src/main/resources/mapper/produce/breed/ScDryMilkMapper.xml index 2304ba9..940aa96 100644 --- a/zhyc-module/src/main/resources/mapper/produce/breed/ScDryMilkMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/breed/ScDryMilkMapper.xml @@ -14,7 +14,6 @@ - @@ -33,17 +32,36 @@ + + - diff --git a/zhyc-module/src/main/resources/mapper/produce/breed/ScSheepDeathMapper.xml b/zhyc-module/src/main/resources/mapper/produce/breed/ScSheepDeathMapper.xml index 8585ad1..f64dd6f 100644 --- a/zhyc-module/src/main/resources/mapper/produce/breed/ScSheepDeathMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/breed/ScSheepDeathMapper.xml @@ -22,37 +22,121 @@ + + + + + + + + + + + - select id, sheep_id, manage_tags, event_type, death_date, disease_type_id, disease_subtype_id, disposal_direction, technician, handler, work_group, create_by, create_time, comment, update_by, update_time, is_delete from sc_sheep_death + select d.id, d.sheep_id, d.manage_tags, d.event_type, d.death_date, d.disease_type_id, d.disease_subtype_id, + d.disposal_direction, d.technician, d.handler, d.work_group, d.create_by, d.create_time, d.comment, + d.update_by, d.update_time, d.is_delete, + s.variety, s.name as sheep_type_name, s.gender, s.day_age, s.parity, s.sheepfold_name, + s.breed as breed_status, s.post_lambing_day, s.lactation_day, s.gestation_day + from sc_sheep_death d + left join sheep_file s on d.manage_tags = s.bs_manage_tags + + + + + + - and wr.sheep_id = #{sheepId} - and sf.bs_manage_tags like concat('%', #{earNumber}, '%') - and wr.datetime = #{datetime} + + + AND sf.bs_manage_tags IN + + #{ear} + + + + and sf.bs_manage_tags like concat('%', #{earNumber}, '%') + + + + AND date_format(wr.datetime,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') + + + AND date_format(wr.datetime,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') + + + + AND sf.status = #{isInHerd} + + + + AND sf.breed = #{sheepCategory} + + and wr.weight = #{weight} and wr.status = #{status} and wr.technician like concat('%', #{technician}, '%') @@ -59,23 +81,27 @@ and sf.father_manage_tags like concat('%', #{fatherNumber}, '%') and sf.mother_manage_tags like concat('%', #{motherNumber}, '%') and sf.sheepfold_name like concat('%', #{sheepPen}, '%') - and sf.breed = #{breedingStatus} order by wr.create_time desc - + + - - insert into sc_wean_record @@ -102,7 +128,6 @@ - update sc_wean_record @@ -119,23 +144,10 @@ where id = #{id} - - - update bas_sheep - - weaning_date = #{datetime}, - weaning_weight = #{weight}, - electronic_tags = #{electronicTags}, - - where manage_tags = #{earNumber} - - - delete from sc_wean_record where id = #{id} - delete from sc_wean_record where id in From b47aa9b269508db4fcfaa87cdb6bab98100ddc87 Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Mon, 2 Feb 2026 00:04:33 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=B9=B2=E5=A5=B6=E5=BD=95=E5=85=A5?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../breed/controller/ScDryMilkController.java | 32 +++- .../produce/breed/domain/ScDryMilk.java | 147 ++++++++++++++++-- .../produce/breed/mapper/ScDryMilkMapper.java | 9 +- .../breed/service/IScDryMilkService.java | 9 +- .../service/impl/ScDryMilkServiceImpl.java | 21 ++- .../mapper/produce/breed/ScDryMilkMapper.xml | 26 +++- 6 files changed, 208 insertions(+), 36 deletions(-) diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScDryMilkController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScDryMilkController.java index c308db0..7b8913e 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScDryMilkController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScDryMilkController.java @@ -49,16 +49,24 @@ public class ScDryMilkController extends BaseController public TableDataInfo list(ScDryMilk scDryMilk) { try { - // 兼容逻辑:如果前端传了字符串形式的耳号(如导出或老接口调用),也转为List + // 处理耳号多选:将逗号/空格分隔的字符串转为List if (scDryMilk.getManageTags() != null && !scDryMilk.getManageTags().trim().isEmpty()) { if (scDryMilk.getManageTagsList() == null) { scDryMilk.setManageTagsList(new ArrayList<>()); } - // 支持中文逗号、英文逗号、空格分割 String[] tags = scDryMilk.getManageTags().trim().split("[,,\\s]+"); scDryMilk.getManageTagsList().addAll(Arrays.asList(tags)); } + // 处理技术员多选:将逗号分隔的字符串转为List + if (scDryMilk.getTecahnician() != null && !scDryMilk.getTecahnician().trim().isEmpty()) { + if (scDryMilk.getTechnicianList() == null) { + scDryMilk.setTechnicianList(new ArrayList<>()); + } + String[] techs = scDryMilk.getTecahnician().trim().split("[,,\\s]+"); + scDryMilk.getTechnicianList().addAll(Arrays.asList(techs)); + } + startPage(); List list = scDryMilkService.selectScDryMilkList(scDryMilk); return getDataTable(list); @@ -75,11 +83,21 @@ public class ScDryMilkController extends BaseController public AjaxResult searchEarNumbers(@RequestParam(value = "query", required = false) String query) { if (query == null) query = ""; - // 调用Service层 List list = scDryMilkService.selectSheepEarNumberList(query); return AjaxResult.success(list); } + /** + * 远程搜索技术员列表 + */ + @GetMapping("/searchTechnicians") + public AjaxResult searchTechnicians(@RequestParam(value = "query", required = false) String query) + { + if (query == null) query = ""; + List list = scDryMilkService.selectTechnicianList(query); + return AjaxResult.success(list); + } + /** * 导出干奶记录列表 */ @@ -89,10 +107,16 @@ public class ScDryMilkController extends BaseController public void export(HttpServletResponse response, ScDryMilk scDryMilk) { try { + // 导出也需要支持多选查询 if (scDryMilk.getManageTags() != null) { String[] tags = scDryMilk.getManageTags().trim().split("[,,\\s]+"); scDryMilk.setManageTagsList(Arrays.asList(tags)); } + if (scDryMilk.getTecahnician() != null) { + String[] techs = scDryMilk.getTecahnician().trim().split("[,,\\s]+"); + scDryMilk.setTechnicianList(Arrays.asList(techs)); + } + List list = scDryMilkService.selectScDryMilkList(scDryMilk); ExcelUtil util = new ExcelUtil(ScDryMilk.class); util.exportExcel(response, list, "干奶记录数据"); @@ -122,7 +146,7 @@ public class ScDryMilkController extends BaseController } /** - * 新增干奶记录 + * 新增干奶记录 (支持批量录入) */ @PreAuthorize("@ss.hasPermi('drymilk:drymilk:add')") @Log(title = "干奶记录", businessType = BusinessType.INSERT) diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScDryMilk.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScDryMilk.java index b093e2f..5c0f51f 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScDryMilk.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/domain/ScDryMilk.java @@ -3,9 +3,8 @@ package com.zhyc.module.produce.breed.domain; import java.util.Date; import java.util.List; import com.fasterxml.jackson.annotation.JsonFormat; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +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; @@ -15,9 +14,6 @@ import com.zhyc.common.core.domain.BaseEntity; * @author ruoyi * @date 2025-07-15 */ -@Data -@NoArgsConstructor -@AllArgsConstructor public class ScDryMilk extends BaseEntity { private static final long serialVersionUID = 1L; @@ -50,13 +46,13 @@ public class ScDryMilk extends BaseEntity @Excel(name = "备注") private String comment; - // --- 联表查询字段 --- + // --- 联表查询及辅助字段 --- - /** 管理耳号 (单个) */ + /** 管理耳号 (单个,用于接收前端传参或导出显示) */ @Excel(name = "耳号") private String manageTags; - /** 多耳号查询列表 (核心修改:用于接收前端多选的数组) */ + /** 多耳号查询列表 (用于MyBatis IN查询) */ private List manageTagsList; /** 品种 */ @@ -70,4 +66,137 @@ public class ScDryMilk extends BaseEntity /** 事件类型 */ @Excel(name = "事件类型") private String eventType; + + /** 技术员多选列表 (新增:用于MyBatis IN查询) */ + private List technicianList; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setSheepId(String sheepId) + { + this.sheepId = sheepId; + } + + public String getSheepId() + { + return sheepId; + } + public void setDatetime(Date datetime) + { + this.datetime = datetime; + } + + public Date getDatetime() + { + return datetime; + } + public void setStatus(Long status) + { + this.status = status; + } + + public Long getStatus() + { + return status; + } + public void setSheepfold(Long sheepfold) + { + this.sheepfold = sheepfold; + } + + public Long getSheepfold() + { + return sheepfold; + } + public void setTecahnician(String tecahnician) + { + this.tecahnician = tecahnician; + } + + public String getTecahnician() + { + return tecahnician; + } + public void setComment(String comment) + { + this.comment = comment; + } + + public String getComment() + { + return comment; + } + + public String getManageTags() { + return manageTags; + } + + public void setManageTags(String manageTags) { + this.manageTags = manageTags; + } + + public List getManageTagsList() { + return manageTagsList; + } + + public void setManageTagsList(List manageTagsList) { + this.manageTagsList = manageTagsList; + } + + public String getVariety() { + return variety; + } + + public void setVariety(String variety) { + this.variety = variety; + } + + public String getSheepfoldName() { + return sheepfoldName; + } + + public void setSheepfoldName(String sheepfoldName) { + this.sheepfoldName = sheepfoldName; + } + + public String getEventType() { + return eventType; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public List getTechnicianList() { + return technicianList; + } + + public void setTechnicianList(List technicianList) { + this.technicianList = technicianList; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("sheepId", getSheepId()) + .append("datetime", getDatetime()) + .append("status", getStatus()) + .append("sheepfold", getSheepfold()) + .append("tecahnician", getTecahnician()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("comment", getComment()) + .append("manageTags", getManageTags()) + .append("variety", getVariety()) + .append("sheepfoldName", getSheepfoldName()) + .toString(); + } } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScDryMilkMapper.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScDryMilkMapper.java index 97440c0..a49f6bf 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScDryMilkMapper.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/mapper/ScDryMilkMapper.java @@ -59,9 +59,12 @@ public interface ScDryMilkMapper public Long selectSheepIdByManageTags(String manageTags); /** - * 远程搜索耳号列表 (新增) - * @param query 搜索关键字 - * @return 耳号列表 + * 远程搜索耳号列表 */ public List selectSheepEarNumberList(@Param("query") String query); + + /** + * 远程搜索技术员列表 + */ + public List searchTechnicianList(@Param("query") String query); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScDryMilkService.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScDryMilkService.java index 6c05394..5b3b4e7 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScDryMilkService.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/IScDryMilkService.java @@ -58,9 +58,12 @@ public interface IScDryMilkService public Long selectSheepIdByManageTags(String manageTags); /** - * 远程搜索耳号列表 (新增方法) - * @param query 搜索关键字 - * @return 耳号列表 + * 远程搜索耳号列表 */ public List selectSheepEarNumberList(String query); + + /** + * 远程搜索技术员列表 + */ + public List selectTechnicianList(String query); } \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScDryMilkServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScDryMilkServiceImpl.java index 548fc78..d699682 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScDryMilkServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/service/impl/ScDryMilkServiceImpl.java @@ -72,13 +72,11 @@ public class ScDryMilkServiceImpl implements IScDryMilkService @Override public int deleteScDryMilkByIds(Long[] ids) { - // 假设ids是Long数组,需要转为String[]传给Mapper,或者修改Mapper接收Long[] - // 这里根据Mapper XML通常接收String[]或Array的习惯,做个转换 - String[] stringIds = new String[ids.length]; - for(int i=0;i selectSheepEarNumberList(String query) { return scDryMilkMapper.selectSheepEarNumberList(query); } + + @Override + public List selectTechnicianList(String query) { + return scDryMilkMapper.searchTechnicianList(query); + } } \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/produce/breed/ScDryMilkMapper.xml b/zhyc-module/src/main/resources/mapper/produce/breed/ScDryMilkMapper.xml index 940aa96..6183ba6 100644 --- a/zhyc-module/src/main/resources/mapper/produce/breed/ScDryMilkMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/breed/ScDryMilkMapper.xml @@ -34,24 +34,33 @@ AND s.bs_manage_tags IN - - #{item} + + #{tag} AND s.bs_manage_tags like concat('%', #{manageTags}, '%') + + AND d.tecahnician IN + + #{tech} + + + + AND d.tecahnician like concat('%', #{tecahnician}, '%') + + - AND d.datetime >= #{params.beginTime} + AND date_format(d.datetime,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') - AND d.datetime <= #{params.endTime} + AND date_format(d.datetime,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') and d.status = #{status} and d.sheepfold = #{sheepfold} - and d.tecahnician like concat('%', #{tecahnician}, '%') and s.variety like concat('%', #{variety}, '%') order by d.datetime desc @@ -64,6 +73,13 @@ LIMIT 20 + + @@ -46,6 +46,8 @@ AND datetime <= #{params.endTime} + + ${params.dataScope} @@ -74,6 +76,8 @@ commnet, create_by, create_time, + user_id, + dept_id, #{source}, @@ -93,6 +97,8 @@ #{commnet}, #{createBy}, #{createTime}, + #{userId}, + #{deptId}, diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/NpMilkInOutStoreMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/NpMilkInOutStoreMapper.xml index ea5eb4c..79dce7f 100644 --- a/zhyc-module/src/main/resources/mapper/dairyProducts/NpMilkInOutStoreMapper.xml +++ b/zhyc-module/src/main/resources/mapper/dairyProducts/NpMilkInOutStoreMapper.xml @@ -1,7 +1,7 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> @@ -93,8 +95,8 @@ - INSERT INTO np_milk_prod_classes (datetime, sheep_id, classes, milk, corrected_milk) - VALUES (#{datetime}, #{sheepId}, #{classes}, #{milk}, #{correctedMilk}) + INSERT INTO np_milk_prod_classes (datetime, sheep_id, classes, milk, corrected_milk, user_id, dept_id) + VALUES (#{datetime}, #{sheepId}, #{classes}, #{milk}, #{correctedMilk}, #{userId}, #{deptId}) @@ -47,6 +47,8 @@ and datetime <= #{params.endTime} and source like concat('%', #{source}, '%') + + ${params.dataScope} @@ -80,6 +82,8 @@ comment, create_by, create_time, + user_id, + dept_id, #{datetime}, @@ -104,6 +108,8 @@ #{comment}, #{createBy}, #{createTime}, + #{userId}, + #{deptId}, diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/NpYogurtInspMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/NpYogurtInspMapper.xml index 0d47254..3de536a 100644 --- a/zhyc-module/src/main/resources/mapper/dairyProducts/NpYogurtInspMapper.xml +++ b/zhyc-module/src/main/resources/mapper/dairyProducts/NpYogurtInspMapper.xml @@ -30,7 +30,7 @@ acidity, bacterial_colony_1, bacterial_clony_2, bacterial_clony_3, bacterial_clony_4, bacterial_clony_5, yeast, mould, lacto, comment, create_by, create_time - from np_yogurt_insp + from np_yogurt_insp a @@ -73,6 +75,8 @@ comment, create_by, create_time, + user_id, + dept_id, #{source}, @@ -92,6 +96,8 @@ #{comment}, #{createBy}, #{createTime}, + #{userId}, + #{deptId}, @@ -105,7 +111,7 @@ non_fat = #{nonFat}, acidity = #{acidity}, bacterial_colony_1 = #{bacterialColony1}, - bacterial_clony_2 = #{bacterialClony2}, + bacterial_colony_2 = #{bacterialClony2}, bacterial_clony_3 = #{bacterialClony3}, bacterial_clony_4 = #{bacterialClony4}, bacterial_clony_5 = #{bacterialClony5}, diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml index 37ae656..7470d16 100644 --- a/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml +++ b/zhyc-module/src/main/resources/mapper/dairyProducts/XzDryMatterCorrectionMapper.xml @@ -11,51 +11,56 @@ + + SELECT - id, - datetime, - factory, - content, - COALESCE(standard, 18) as standard, + d.id, + d.datetime, + d.factory, + d.content, + COALESCE(d.standard, 18) as standard, CASE - WHEN standard = 0 OR standard IS NULL THEN NULL - ELSE ROUND(content / standard, 2) - END AS coefficient - FROM xz_dry_matter_correction + WHEN d.standard = 0 OR d.standard IS NULL THEN NULL + ELSE ROUND(d.content / d.standard, 2) + END AS coefficient, + d.user_id, + d.dept_id + FROM xz_dry_matter_correction d INSERT INTO xz_dry_matter_correction - datetime, factory, content, standard + datetime, factory, content, standard, user_id, dept_id - #{datetime}, #{factory}, #{content}, #{standard} + #{datetime}, #{factory}, #{content}, #{standard}, #{userId}, #{deptId} diff --git a/zhyc-module/src/main/resources/mapper/dairyProducts/XzWegihCorrectionMapper.xml b/zhyc-module/src/main/resources/mapper/dairyProducts/XzWegihCorrectionMapper.xml index 30d5155..a0b13fa 100644 --- a/zhyc-module/src/main/resources/mapper/dairyProducts/XzWegihCorrectionMapper.xml +++ b/zhyc-module/src/main/resources/mapper/dairyProducts/XzWegihCorrectionMapper.xml @@ -11,38 +11,44 @@ + + select - id, - datetime, - factory, - actual, - system_milk, + w.id, + w.datetime, + w.factory, + w.actual, + w.system_milk, CASE - WHEN system_milk = 0 THEN 0 - ELSE ROUND(actual / system_milk, 4) - END as coefficient - from xz_wegih_correction + WHEN w.system_milk = 0 THEN 0 + ELSE ROUND(w.actual / w.system_milk, 4) + END as coefficient, + w.user_id, + w.dept_id + from xz_wegih_correction w @@ -52,12 +58,14 @@ factory, actual, system_milk, + user_id, dept_id #{datetime}, #{factory}, #{actual}, #{systemMilk}, + #{userId}, #{deptId} From 9ed2039df0a7facf532ea6bc42196715da28419a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BC=82=E6=B3=8A?= <1913856125@qq.com> Date: Tue, 3 Feb 2026 22:14:57 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E8=80=B3=E5=8F=B7=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=B9=E9=87=8F=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/controller/BasSheepController.java | 63 +++++++++++++++---- .../module/base/mapper/BasSheepMapper.java | 6 +- .../module/base/service/IBasSheepService.java | 6 ++ .../service/impl/BasSheepServiceImpl.java | 18 +++++- .../biosafety/domain/QuarantineReport.java | 23 +++++-- .../impl/QuarantineReportServiceImpl.java | 1 + .../resources/mapper/base/BasSheepMapper.xml | 24 ++++++- .../resources/mapper/base/DaRanchMapper.xml | 12 ++-- .../biosafety/QuarantineReportMapper.xml | 5 +- 9 files changed, 127 insertions(+), 31 deletions(-) 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 3466b17..edbabb6 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,9 +1,7 @@ package com.zhyc.module.base.controller; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; import com.zhyc.module.base.domain.BasSheep; @@ -110,20 +108,61 @@ public class BasSheepController extends BaseController { } /** - * 根据耳号查询 + * 批量查询羊只耳号状态 */ @GetMapping("/byManageTags/{manageTags}") public AjaxResult byManageTags(@PathVariable String manageTags) { - BasSheep sheep = basSheepService.selectBasSheepByManageTags(manageTags.trim()); - if (sheep == null) { - return error("未找到对应的羊只"); + if (manageTags == null || manageTags.trim().isEmpty()) { + return error("管理耳号不能为空"); } - // 补品种名称 - BasSheepVariety variety = basSheepVarietyService.selectBasSheepVarietyById(sheep.getVarietyId()); - sheep.setVarietyName(variety == null ? "" : variety.getVariety()); + // 批量查询模式 - 使用空格或逗号分割 + String[] tags = manageTags.split("[\\s,,]+"); - return success(sheep); + try { + // 过滤掉空值并去重 + List validTags = Arrays.stream(tags) + .map(String::trim) + .filter(tag -> !tag.isEmpty()) + .distinct() + .collect(Collectors.toList()); + + if (validTags.isEmpty()) { + return error("有效的耳号不能为空"); + } + + // 查询所有存在的羊只 + List existingSheep = basSheepService.selectBasSheepByManageTagsList(validTags); + + Set existingTagSet = existingSheep.stream() + .map(BasSheep::getManageTags) + .collect(Collectors.toSet()); + + // 分别统计在羊群和不在羊群的耳号 + List inHerd = new ArrayList<>(); + List notInHerd = new ArrayList<>(); + + for (String tag : validTags) { + if (existingTagSet.contains(tag)) { + inHerd.add(tag); + } else { + notInHerd.add(tag); + } + } + + Map result = new HashMap<>(); + result.put("inHerd", inHerd); + result.put("notInHerd", notInHerd); + result.put("total", validTags.size()); + result.put("inHerdCount", inHerd.size()); + result.put("notInHerdCount", notInHerd.size()); + result.put("sheepDetails", existingSheep); + + return success(result); + } catch (Exception e) { + logger.error("批量查询羊只状态异常", e); + return error("批量查询失败:" + e.getMessage()); + } } /** 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 7027dca..85d63dc 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 @@ -2,6 +2,7 @@ package com.zhyc.module.base.mapper; import java.util.List; +import com.zhyc.common.core.domain.BaseEntity; import com.zhyc.module.base.domain.BasSheep; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -73,10 +74,10 @@ public interface BasSheepMapper /** * 模糊查询母羊耳号列表 * - * @param query 查询关键字 + * @param sheep 查询关键字 * @return 耳号列表 */ - List searchEarNumbers(@Param("query") String query); + List searchEarNumbers(BasSheep sheep); List selectBasSheepBySheepfold(String id); @@ -91,4 +92,5 @@ public interface BasSheepMapper int existsByElectronicTag(@Param("tag") String tag); + List selectBasSheepByManageTagsList(@Param("manageTagsList") List manageTagsList, @Param("sheep")BasSheep sheep); } 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 0d1b0c4..50dc6bd 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 @@ -71,6 +71,12 @@ public interface IBasSheepService * 根据羊只耳号获取羊只 */ BasSheep selectBasSheepByManageTags(String trim); + /** + * 根据管理耳号列表批量查询羊只 + */ + List selectBasSheepByManageTagsList(List manageTagsList); + + /** * 根据牧场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 bff0d19..a28aa14 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 @@ -1,8 +1,10 @@ package com.zhyc.module.base.service.impl; +import java.util.ArrayList; import java.util.List; import com.zhyc.common.annotation.DataScope; +import com.zhyc.common.core.domain.BaseEntity; import com.zhyc.common.utils.DateUtils; import com.zhyc.module.base.domain.BasSheep; import com.zhyc.module.base.mapper.BasSheepMapper; @@ -53,10 +55,22 @@ public class BasSheepServiceImpl implements IBasSheepService * @return */ @Override - @DataScope(deptAlias = "b", userAlias = "b") + @DataScope(deptAlias = "s", userAlias = "s") public List searchEarNumbers(String query) { - return basSheepMapper.searchEarNumbers(query); + BasSheep basSheep = new BasSheep(); + basSheep.setManageTags(query); + return basSheepMapper.searchEarNumbers(basSheep); } + + @Override + @DataScope(deptAlias = "s", userAlias = "s") + public List selectBasSheepByManageTagsList(List manageTagsList) { + if (manageTagsList == null || manageTagsList.isEmpty()) { + return new ArrayList<>(); + } + return basSheepMapper.selectBasSheepByManageTagsList(manageTagsList,new BasSheep()); +} + /** * 新增羊只基本信息 * diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/QuarantineReport.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/QuarantineReport.java index ee9f277..5b2a5f4 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/QuarantineReport.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/domain/QuarantineReport.java @@ -42,6 +42,12 @@ public class QuarantineReport extends BaseEntity /** 全部羊耳号列表(用于多耳号查询) */ private List allEarNumbers; + @Excel(name = "品种") + private String variety; + /** 检疫日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "检疫日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date datetime; @Excel(name = "羊只类别") private String sheepType; @@ -56,10 +62,7 @@ public class QuarantineReport extends BaseEntity private String breed; - /** 检疫日期 */ - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "检疫日期", width = 30, dateFormat = "yyyy-MM-dd") - private Date datetime; + /** 检疫项目 */ @@ -103,7 +106,17 @@ public class QuarantineReport extends BaseEntity public void setGender(String gender) { this.gender = gender; - this.genderName = Gender.getDescByCode(Integer.valueOf(gender)); + if (gender != null && !gender.trim().isEmpty()) { + try { + Integer genderCode = Integer.valueOf(gender.trim()); + this.genderName = Gender.getDescByCode(genderCode); + } catch (NumberFormatException e) { + // 如果转换失败,设置为空或默认值 + this.genderName = null; + } + } else { + this.genderName = null; + } } // 排序查询 diff --git a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/QuarantineReportServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/QuarantineReportServiceImpl.java index 87148e0..8023f7d 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/QuarantineReportServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/biosafety/service/impl/QuarantineReportServiceImpl.java @@ -85,6 +85,7 @@ public class QuarantineReportServiceImpl implements IQuarantineReportService BeanUtils.copyProperties(quarantineReport, quarantine); quarantine.setSheepId(sheepFile.getId()); quarantine.setSheepNo(sheepFile.getElectronicTags()); + quarantine.setVariety(sheepFile.getVariety() != null ? sheepFile.getVariety() : ""); quarantine.setSheepType(sheepFile.getName()); // 性别前端处理 diff --git a/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml b/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml index 1c81ab7..93abbc6 100644 --- a/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml +++ b/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml @@ -152,7 +152,7 @@ SELECT DISTINCT manage_tags FROM bas_sheep b - manage_tags LIKE CONCAT(#{query}, '%') + manage_tags LIKE CONCAT(#{manageTags}, '%') AND is_delete = 0 ${params.dataScope} @@ -165,8 +165,26 @@ bv.variety AS varietyName FROM bas_sheep s LEFT JOIN bas_sheep_variety bv ON s.variety_id = bv.id - WHERE s.manage_tags = #{manageTags} - AND s.is_delete = 0 LIMIT 1 + s.manage_tags = #{manageTags} + AND s.is_delete = 0 + ${params.dataScope} + + + + + - and sysRanch = #{sysRanch} + and ranch = #{ranch} @@ -29,17 +29,17 @@ insert into da_ranch - sysRanch, + ranch, - #{sysRanch}, + #{ranch}, update da_ranch - sysRanch = #{sysRanch}, + ranch = #{ranch}, where id = #{id} diff --git a/zhyc-module/src/main/resources/mapper/biosafety/QuarantineReportMapper.xml b/zhyc-module/src/main/resources/mapper/biosafety/QuarantineReportMapper.xml index d16f22d..b678dbf 100644 --- a/zhyc-module/src/main/resources/mapper/biosafety/QuarantineReportMapper.xml +++ b/zhyc-module/src/main/resources/mapper/biosafety/QuarantineReportMapper.xml @@ -8,6 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -30,7 +31,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select sqr.id, sheep_type,sqr.gender,sqr.parity,sqr.breed,sqr.month_age,sheep_id, datetime, quar_item, sample_type, sampler, quar_officer, result, status, + select sqr.id, sheep_type,sqr.variety,sqr.gender,sqr.parity,sqr.breed,sqr.month_age,sheep_id, datetime, quar_item, sample_type, sampler, quar_officer, result, status, sqr.update_by, sqr.update_time, sqr.create_by, sqr.create_time, sqi.name as item_name, sqs.name as sample, @@ -98,6 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" INSERT INTO sw_quarantine_report ( sheep_id, + variety, sheep_type, month_age, parity, @@ -121,6 +123,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ( #{item.sheepId}, + #{item.variety}, #{item.sheepType}, #{item.monthAge}, #{item.parity}, From 68ea3b2721a21a4664cfe5978b5adc94b3110e95 Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Tue, 3 Feb 2026 22:22:21 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=96=AD=E5=A5=B6bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../breed/controller/ScWeanRecordController.java | 14 -------------- .../mapper/produce/breed/ScWeanRecordMapper.xml | 9 --------- 2 files changed, 23 deletions(-) diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScWeanRecordController.java b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScWeanRecordController.java index 23e0cb7..4579927 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScWeanRecordController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/produce/breed/controller/ScWeanRecordController.java @@ -130,18 +130,4 @@ public class ScWeanRecordController extends BaseController { } - /** - * 模糊查询母羊耳号列表 - */ - @PreAuthorize("@ss.hasPermi('breed:lambing_records:query')") // 根据实际权限修改 - @GetMapping("/search_ear_numbers") - public AjaxResult searchEarNumbers(@RequestParam("query") String query) { - try { - List earNumbers = scWeanRecordService.searchEarNumbers(query); - return success(earNumbers); - } catch (Exception e) { - logger.error("搜索耳号异常", e); - return error("搜索耳号失败:" + e.getMessage()); - } - } } \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/produce/breed/ScWeanRecordMapper.xml b/zhyc-module/src/main/resources/mapper/produce/breed/ScWeanRecordMapper.xml index 7fb8b2b..4ea385d 100644 --- a/zhyc-module/src/main/resources/mapper/produce/breed/ScWeanRecordMapper.xml +++ b/zhyc-module/src/main/resources/mapper/produce/breed/ScWeanRecordMapper.xml @@ -164,13 +164,4 @@ - - \ No newline at end of file From 51d1c5d1456918ea9d9b654d439f3a251ac1de00 Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Wed, 4 Feb 2026 17:35:48 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E7=BE=8A=E5=8F=AA=E6=A1=A3=E6=A1=88?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/controller/SheepFileController.java | 164 +++++--- .../zhyc/module/base/domain/SheepFile.java | 31 +- .../module/base/mapper/SheepFileMapper.java | 68 ++-- .../base/service/ISheepFileService.java | 36 +- .../service/impl/SheepFileServiceImpl.java | 162 +++----- .../resources/mapper/base/SheepFileMapper.xml | 359 ++++++++++++++---- 6 files changed, 523 insertions(+), 297 deletions(-) diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/controller/SheepFileController.java b/zhyc-module/src/main/java/com/zhyc/module/base/controller/SheepFileController.java index 6391bc2..24a0880 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/controller/SheepFileController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/controller/SheepFileController.java @@ -10,23 +10,18 @@ import com.zhyc.common.enums.BusinessType; import com.zhyc.common.utils.poi.ExcelUtil; import com.zhyc.module.base.domain.SheepFile; import com.zhyc.module.base.service.ISheepFileService; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; -import javax.servlet.http.HttpServletRequest; +import java.util.*; /** * 羊只档案Controller - * - * @author wyt + * * @author wyt * @date 2025-07-13 */ @RestController @@ -52,7 +47,7 @@ public class SheepFileController extends BaseController Integer pageSize = 10; if (queryParams != null && !queryParams.isEmpty()) { - // 提取分页参数 + // ------------------ 1. 处理分页参数 ------------------ if (queryParams.containsKey("pageNum") && queryParams.get("pageNum") != null) { try { pageNum = Integer.parseInt(queryParams.get("pageNum").toString()); @@ -60,7 +55,6 @@ public class SheepFileController extends BaseController // 使用默认值 } } else if (queryParams.containsKey("page") && queryParams.get("page") != null) { - // 如果 pageNum 不存在,则尝试使用 page try { pageNum = Integer.parseInt(queryParams.get("page").toString()); } catch (NumberFormatException e) { @@ -68,15 +62,13 @@ public class SheepFileController extends BaseController } } - if (queryParams.containsKey("pageSize") && queryParams.get("pageSize") != null) { try { pageSize = Integer.parseInt(queryParams.get("pageSize").toString()); } catch (NumberFormatException e) { // 使用默认值 } - }else if (queryParams.containsKey("limit") && queryParams.get("limit") != null) { - // 如果 pageSize 不存在,则尝试使用 limit + } else if (queryParams.containsKey("limit") && queryParams.get("limit") != null) { try { pageSize = Integer.parseInt(queryParams.get("limit").toString()); } catch (NumberFormatException e) { @@ -84,7 +76,25 @@ public class SheepFileController extends BaseController } } - // 提取常规查询参数到 SheepFile 对象 + // ------------------ 2. 核心修复:处理 List 多选参数 ------------------ + // 使用 parseList 方法兼容处理 List、Array、逗号分隔字符串 + sheepFile.setAllEarNumbers(parseList(queryParams.get("allEarNumbers"))); + sheepFile.setAllEleEarNumbers(parseList(queryParams.get("allEleEarNumbers"))); + sheepFile.setAllBreedingStatus(parseList(queryParams.get("allBreedingStatus"))); + sheepFile.setAllSheepTypes(parseList(queryParams.get("allSheepTypes"))); + + // 性别处理 (需要将 String/Integer 转为 Long) + List genderStrs = parseList(queryParams.get("allGenders")); + if (genderStrs != null && !genderStrs.isEmpty()) { + List genderLongs = new ArrayList<>(); + for (String s : genderStrs) { + Long v = convertToLong(s); + if(v != null) genderLongs.add(v); + } + sheepFile.setAllGenders(genderLongs); + } + + // ------------------ 3. 处理常规单值参数 ------------------ if (queryParams.containsKey("bsManageTags") && queryParams.get("bsManageTags") != null) { sheepFile.setBsManageTags(queryParams.get("bsManageTags").toString()); } @@ -110,23 +120,17 @@ public class SheepFileController extends BaseController sheepFile.setBreed(queryParams.get("breed").toString()); } - // 移除已经处理的参数,剩下的作为自定义筛选参数 + // ------------------ 4. 提取自定义参数 (排除已处理的键) ------------------ + // 定义需要跳过的key,防止重复处理 + Set processedKeys = new HashSet<>(Arrays.asList( + "pageNum", "pageSize", "page", "limit", + "bsManageTags", "electronicTags", "drRanch", "variety", "name", "gender", "statusId", "breed", + "allEarNumbers", "allEleEarNumbers", "allGenders", "allBreedingStatus", "allSheepTypes" + )); + for (Map.Entry entry : queryParams.entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); - - // 跳过常规参数和分页参数 - if ("bsManageTags".equals(key) || "electronicTags".equals(key) || - "drRanch".equals(key) || "variety".equals(key) || - "name".equals(key) || "gender".equals(key) || - "statusId".equals(key) || "breed".equals(key) || - "pageNum".equals(key) || "pageSize".equals(key)) { - continue; - } - - // 添加到自定义参数中 - if (value != null) { - customParams.put(key, value); + if (!processedKeys.contains(entry.getKey()) && entry.getValue() != null) { + customParams.put(entry.getKey(), entry.getValue()); } } } @@ -139,6 +143,41 @@ public class SheepFileController extends BaseController return getDataTable(list); } + + /** + * 辅助方法:统一解析各种格式的数组参数 + * 支持:List, String[] (数组), Object[] (数组), "A,B" (逗号分隔字符串) + */ + private List parseList(Object obj) { + if (obj == null) return null; + List result = new ArrayList<>(); + + if (obj instanceof List) { + // JSON 传来的通常是 List + for (Object o : (List) obj) { + if (o != null) result.add(o.toString()); + } + } else if (obj.getClass().isArray()) { + // 如果是数组 + if (obj instanceof Object[]) { + for (Object o : (Object[]) obj) { + if (o != null) result.add(o.toString()); + } + } else if (obj instanceof String[]) { + Collections.addAll(result, (String[]) obj); + } + } else if (obj instanceof String) { + // 如果是逗号分隔字符串 + String s = (String) obj; + if (StringUtils.isNotBlank(s)) { + String[] split = s.split(","); + Collections.addAll(result, split); + } + } + + return result.isEmpty() ? null : result; + } + /** * 转换对象为Long类型 */ @@ -186,6 +225,7 @@ public class SheepFileController extends BaseController // 使用若依框架的工具方法处理参数 switch (key) { + // --- 单值参数 --- case "bsManageTags": sheepFile.setBsManageTags(convertToString(value)); break; @@ -210,6 +250,30 @@ public class SheepFileController extends BaseController case "breed": sheepFile.setBreed(convertToString(value)); break; + + // --- 新增:处理多选数组参数 --- + // request.getParameterMap 中的值本身就是 String[],可以直接使用 + case "allEarNumbers": + sheepFile.setAllEarNumbers(new ArrayList<>(Arrays.asList(values))); + break; + case "allEleEarNumbers": + sheepFile.setAllEleEarNumbers(new ArrayList<>(Arrays.asList(values))); + break; + case "allBreedingStatus": + sheepFile.setAllBreedingStatus(new ArrayList<>(Arrays.asList(values))); + break; + case "allSheepTypes": + sheepFile.setAllSheepTypes(new ArrayList<>(Arrays.asList(values))); + break; + case "allGenders": + List genderList = new ArrayList<>(); + for(String v : values){ + Long l = Convert.toLong(v); + if(l != null) genderList.add(l); + } + sheepFile.setAllGenders(genderList); + break; + case "pageNum": case "pageSize": // 忽略分页参数 @@ -230,6 +294,14 @@ public class SheepFileController extends BaseController util.exportExcel(response, list, "羊只档案数据"); } + /** + * 新增:模糊搜索耳号接口 (用于前端下拉框远程搜索) + */ + @GetMapping("/searchEarNumbers") + public AjaxResult searchEarNumbers(@RequestParam("query") String query) + { + return success(sheepFileService.searchEarNumbers(query)); + } /** * 字符串转换工具方法 @@ -252,15 +324,14 @@ public class SheepFileController extends BaseController } /* - * 根据耳号查询是否存在羊舍 - * */ + * 根据耳号查询是否存在羊舍 + * */ @GetMapping("/byNo/{manageTags}") public AjaxResult byManageTags(@PathVariable String manageTags){ SheepFile sheep=sheepFileService.selectBasSheepByManageTags(manageTags.trim()); return success(sheep); } - @GetMapping("/stat/sheepType") public AjaxResult statSheepType() { return success(sheepFileService.countBySheepType()); @@ -289,43 +360,18 @@ public class SheepFileController extends BaseController /** * 新增API:获取字段的唯一值列表 - * - * 这个API为前端自定义筛选功能提供数据支持 - * 当用户选择某个字段进行筛选时,前端调用此接口获取该字段的所有可能值 - * - * @param fieldName 字段名(数据库列名) - * @return AjaxResult 包含字段值列表的响应结果 - * - * 接口地址:GET /sheep_file/sheep_file/field/{fieldName} - * - * 使用示例: - * 前端请求:GET /sheep_file/sheep_file/field/bs_manage_tags - * 后端返回:{ "code": 200, "msg": "操作成功", "data": ["AF00001", "AF00002", "AF00003"] } - * - * 安全说明: - * - 使用白名单机制防止SQL注入 - * - 只有预定义的字段名可以被查询 */ @GetMapping("/field/{fieldName}") public AjaxResult getFieldValues(@PathVariable String fieldName) { try { // 调用Service层获取字段唯一值 List fieldValues = sheepFileService.getFieldValues(fieldName); - - // 返回成功响应,包含字段值列表 return AjaxResult.success("获取字段值成功", fieldValues); - } catch (IllegalArgumentException e) { - // 处理字段名不合法的异常 - // 这种情况通常是因为前端传入了不在白名单中的字段名 return AjaxResult.error("请求的字段名不合法: " + e.getMessage()); - } catch (Exception e) { - // 处理其他未知异常 - // 记录日志并返回友好的错误信息 logger.error("获取字段值失败,字段名: " + fieldName, e); return AjaxResult.error("系统错误,获取字段值失败"); } } - -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/domain/SheepFile.java b/zhyc-module/src/main/java/com/zhyc/module/base/domain/SheepFile.java index 4dc4784..9966094 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/base/domain/SheepFile.java +++ b/zhyc-module/src/main/java/com/zhyc/module/base/domain/SheepFile.java @@ -8,11 +8,11 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.util.Date; +import java.util.List; /** * 羊只档案对象 sheep_file - * - * @author wyt + * * @author wyt * @date 2025-07-13 */ @Data @@ -29,6 +29,10 @@ public class SheepFile extends BaseEntity @Excel(name = "管理耳号") private String bsManageTags; + /** ================= 新增:多选查询字段 ================= */ + /** 耳号集合(多选/模糊查询用) */ + private List allEarNumbers; + /** 牧场id */ // @Excel(name = "牧场id") private Long ranchId; @@ -49,6 +53,10 @@ public class SheepFile extends BaseEntity @Excel(name = "电子耳号") private String electronicTags; + /** ================= 新增:多选查询字段 ================= */ + /** 电子耳号集合(多选查询用) */ + private List allEleEarNumbers; + /** 品种id */ // @Excel(name = "品种id") private Long varietyId; @@ -65,14 +73,22 @@ public class SheepFile extends BaseEntity @Excel(name = "羊只类型") private String name; + /** ================= 新增:多选查询字段 ================= */ + /** 羊只类型集合(多选查询用) */ + private List allSheepTypes; + // /** 性别 */ //// @Excel(name = "性别") // private Long gender; /** 性别 - 使用字典转换 */ - @Excel(name = "性别", dictType = "sheep_gender") // 添加 dictType + @Excel(name = "性别", dictType = "sheep_gender") private Long gender; + /** ================= 新增:多选查询字段 ================= */ + /** 性别集合(多选查询用) */ + private List allGenders; + /** 出生日期 */ @JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "出生日期", width = 30, dateFormat = "yyyy-MM-dd") @@ -103,7 +119,6 @@ public class SheepFile extends BaseEntity @Excel(name = "羊只状态", dictType = "sheep_status") private Long statusId; - /** 断奶体重 */ @Excel(name = "断奶体重") private Double weaningWeight; @@ -129,6 +144,10 @@ public class SheepFile extends BaseEntity @Excel(name = "繁殖状态") private String breed; + /** ================= 新增:多选查询字段 ================= */ + /** 繁殖状态集合(多选查询用) */ + private List allBreedingStatus; + /** 父号id */ // @Excel(name = "父号id") private Long bsFatherId; @@ -300,6 +319,4 @@ public class SheepFile extends BaseEntity @JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "创建日期", width = 30, dateFormat = "yyyy-MM-dd") private Date createTime; - - -} +} \ 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 ad8821e..909955d 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 @@ -27,13 +27,19 @@ public interface SheepFileMapper public SheepFile selectSheepFileById(Long id); /** - * 查询羊只档案列表 + * 查询羊只档案列表 (基础查询) * * @param sheepFile 羊只档案 * @return 羊只档案集合 */ public List selectSheepFileList(SheepFile sheepFile); + /** + * 新增:模糊查询耳号列表(用于下拉框远程搜索) + * @param query 搜索关键字 + * @return 匹配的耳号列表 + */ + List searchEarNumbers(@Param("query") String query); /** * 根据管理耳号查询 @@ -43,11 +49,9 @@ public interface SheepFileMapper */ SheepFile selectSheepByManageTags(String tags); - // 在群羊只总数 Long countInGroup(); - // 羊只类别分布(按 name 分组) List> countBySheepType(); @@ -60,52 +64,34 @@ public interface SheepFileMapper // 泌乳羊胎次分布(name = '泌乳羊' 时按 parity 分组) List> countParityOfLactation(); - /** - * 新增方法:获取指定字段的唯一值列表 - * - * 这个方法用于查询数据库中某个字段的所有不重复的值 - * 主要用于前端筛选条件中的下拉选项数据 - * - * @param fieldName 字段名(数据库表中的列名) - * @return 该字段的所有唯一值列表,按字母顺序排序 - * - * 使用场景示例: - * - 用户选择"耳号"字段时,返回所有不重复的耳号 - * - 用户选择"品种"字段时,返回所有不重复的品种名称 + * 获取指定字段的唯一值列表 (配合 XML 中的 selectFieldValues) */ - List selectFieldValues(String fieldName); + List selectFieldValues(@Param("fieldName") String fieldName); /** - * 根据复杂条件查询羊只档案列表 - * - * @param params 查询参数映射 - * @param sheepFile 原有的查询条件(保持兼容) - * @return 羊只档案列表 + * 核心修复:根据复杂条件查询羊只档案列表 + * 对应 XML 中的 对应的方法 + return sheepFileMapper.selectSheepFileListByCondition(safeConditions, sheepFile); } @Override + @Transactional public int insertSheepFile(SheepFile sheepFile) { + // int rows = sheepFileMapper.insertSheepFile(sheepFile); + // if (rows > 0) { syncToBreedRamFile(sheepFile); } + // return rows; return 0; } @Override + @Transactional public int updateSheepFile(SheepFile sheepFile) { + // int rows = sheepFileMapper.updateSheepFile(sheepFile); + // if (rows > 0) { syncToBreedRamFile(sheepFile); } + // return rows; return 0; } @@ -126,12 +142,13 @@ public class SheepFileServiceImpl implements ISheepFileService { String fieldName = entry.getKey(); Object value = entry.getValue(); - // 将前端字段名转换为数据库字段名 + // 将前端字段名转换为数据库字段名 (例如: fatherManageTags -> father_manage_tags) + // 这对于 XML 中的 ${key} = #{value} 至关重要 String dbFieldName = convertToDbFieldName(fieldName); // 验证字段名是否安全 if (isValidFieldName(dbFieldName)) { - // 处理值,确保不是 Character 类型 + // 处理值 Object safeValue = value; if (value != null) { String strValue = value.toString(); @@ -140,23 +157,17 @@ public class SheepFileServiceImpl implements ISheepFileService { if (strValue.startsWith("GT:") || strValue.startsWith("LT:") || strValue.startsWith("GE:") || strValue.startsWith("LE:")) { String numPart = strValue.substring(3); - // 验证数字部分是否安全(防止 SQL 注入) + // 验证数字部分是否安全 if (isNumeric(numPart)) { safeValue = strValue; } else { - // 如果不是数字,忽略这个条件 - System.out.println("警告:范围条件的值不是数字: " + fieldName + " = " + strValue); continue; } } else { - // 其他值直接使用字符串 safeValue = strValue; } } safeParams.put(dbFieldName, safeValue); - } else { - // 记录日志 - System.out.println("警告:忽略非法字段名: " + fieldName + " -> " + dbFieldName); } } @@ -191,61 +202,17 @@ public class SheepFileServiceImpl implements ISheepFileService { * 扩展字段名白名单验证 */ private boolean isValidFieldName(String fieldName) { - // 扩展允许查询的字段白名单 + // 字段白名单 String[] allowedFields = { - "id", - "bs_manage_tags", // 管理耳号 - "electronic_tags", // 电子耳号 - "dr_ranch", // 牧场名称 - "sheepfold_name", // 羊舍名称 - "variety", // 品种 - "family", // 家系 - "name", // 羊只类型 - "gender", // 性别 - "birthday", // 出生日期 - "day_age", // 日龄 - "month_age", // 月龄 - "parity", // 胎次 - "birth_weight", // 出生体重 - "weaning_date", // 断奶日期 - "status_id", // 羊只状态 - "weaning_weight", // 断奶体重 - "current_weight", // 当前体重 - "weaning_day_age", // 断奶日龄 - "weaning_daily_gain", // 断奶日增重 - "breed", // 繁殖状态 - "father_manage_tags", // 父亲耳号 - "mother_manage_tags", // 母亲耳号 - "receptor_manage_tags", // 受体耳号 - "grandfather_manage_tags", // 祖父耳号 - "grandmother_manage_tags", // 祖母耳号 - "maternal_grandfather_manage_tags", // 外祖父耳号 - "maternal_grandmother_manage_tags", // 外祖母耳号 - "mating_date", // 配种日期 - "mating_type_id", // 配种类型 - "preg_date", // 孕检日期 - "lambing_date", // 产羔日期 - "lambing_day", // 产羔时怀孕天数 - "mating_day", // 配后天数 - "gestation_day", // 怀孕天数 - "expected_date", // 预产日期 - "post_lambing_day", // 产后天数 - "lactation_day", // 泌乳天数 - "anestrous_day", // 空怀天数 - "mating_counts", // 配种次数 - "mating_total", // 累计配种次数 - "miscarriage_counts", // 累计流产次数 - "comment", // 备注 - "controlled", // 是否性控 - "body", // 体况评分 - "breast", // 乳房评分 - "source", // 入群来源 - "source_date", // 入群日期 - "source_ranch", // 来源牧场 - "update_by", // 修改人 - "update_time", // 修改日期 - "create_by", // 创建人 - "create_time" // 创建日期 + "id", "bs_manage_tags", "electronic_tags", "dr_ranch", "sheepfold_name", "variety", "family", + "name", "gender", "birthday", "day_age", "month_age", "parity", "birth_weight", "weaning_date", + "status_id", "weaning_weight", "current_weight", "weaning_day_age", "weaning_daily_gain", "breed", + "father_manage_tags", "mother_manage_tags", "receptor_manage_tags", "grandfather_manage_tags", + "grandmother_manage_tags", "maternal_grandfather_manage_tags", "maternal_grandmother_manage_tags", + "mating_date", "mating_type_id", "preg_date", "lambing_date", "lambing_day", "mating_day", + "gestation_day", "expected_date", "post_lambing_day", "lactation_day", "anestrous_day", + "mating_counts", "mating_total", "miscarriage_counts", "comment", "controlled", "body", "breast", + "source", "source_date", "source_ranch", "update_by", "update_time", "create_by", "create_time" }; for (String allowedField : allowedFields) { @@ -257,45 +224,32 @@ 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) { - // 记录日志,但不影响主流 + e.printStackTrace(); } } - /** - * 将SheepFile转换为BreedRamFile - */ private BreedRamFile convertToBreedRamFile(SheepFile sheepFile) { BreedRamFile breedRamFile = new BreedRamFile(); - // 基本信息 breedRamFile.setOrdinaryEarNumber(sheepFile.getBsManageTags()); breedRamFile.setRanchId(sheepFile.getRanchId()); breedRamFile.setRanchName(sheepFile.getDrRanch()); @@ -307,15 +261,13 @@ public class SheepFileServiceImpl implements ISheepFileService { breedRamFile.setSheepCategory(sheepFile.getName()); breedRamFile.setBirthday(sheepFile.getBirthday()); - // 体重相关 - breedRamFile.setBirthWeight(BigDecimal.valueOf(sheepFile.getBirthWeight())); + if (sheepFile.getBirthWeight() != null) 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())); + if (sheepFile.getWeaningWeight() != null) breedRamFile.setWeaningWeight(BigDecimal.valueOf(sheepFile.getWeaningWeight())); + if (sheepFile.getWeaningDailyGain() != null) breedRamFile.setWeaningDailyGain(BigDecimal.valueOf(sheepFile.getWeaningDailyGain())); + if (sheepFile.getCurrentWeight() != null) breedRamFile.setCurrentWeight(BigDecimal.valueOf(sheepFile.getCurrentWeight())); - // 家系信息 breedRamFile.setFatherNumber(sheepFile.getFatherManageTags()); breedRamFile.setMotherNumber(sheepFile.getMotherManageTags()); breedRamFile.setGrandfatherNumber(sheepFile.getGrandfatherManageTags()); @@ -323,7 +275,6 @@ public class SheepFileServiceImpl implements ISheepFileService { breedRamFile.setMaternalGrandfatherNumber(sheepFile.getMaternalGrandfatherManageTags()); breedRamFile.setMaternalGrandmotherNumber(sheepFile.getMaternalGrandmotherManageTags()); - // 审计信息 breedRamFile.setCreateBy(sheepFile.getCreateBy()); breedRamFile.setCreateTime(sheepFile.getCreateTime()); breedRamFile.setUpdateBy(sheepFile.getUpdateBy()); @@ -332,5 +283,4 @@ public class SheepFileServiceImpl implements ISheepFileService { return breedRamFile; } - -} +} \ 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 1d6964c..c897edb 100644 --- a/zhyc-module/src/main/resources/mapper/base/SheepFileMapper.xml +++ b/zhyc-module/src/main/resources/mapper/base/SheepFileMapper.xml @@ -1,9 +1,9 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -79,7 +79,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + + + + - - - - - - - - - - FROM sheep_file - - AND is_delete = 0 + AND (is_delete = 0 OR is_delete IS NULL) - - + + AND bs_manage_tags IN + + #{item} + + + + AND electronic_tags IN + + #{item} + + + + AND gender IN + + #{item} + + + + AND breed IN + + #{item} + + + + AND name IN + + #{item} + + + + AND bs_manage_tags LIKE CONCAT('%', #{sheepFile.bsManageTags}, '%') - + AND electronic_tags LIKE CONCAT('%', #{sheepFile.electronicTags}, '%') @@ -183,23 +204,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND variety LIKE CONCAT('%', #{sheepFile.variety}, '%') - + AND name LIKE CONCAT('%', #{sheepFile.name}, '%') - + AND gender = #{sheepFile.gender} AND status_id = #{sheepFile.statusId} - + AND breed LIKE CONCAT('%', #{sheepFile.breed}, '%') - - AND ${key} IS NULL @@ -207,12 +226,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND ${key} IS NOT NULL - - - - - + AND ${key} > #{value.toString().substring(3)} @@ -228,21 +243,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - - + AND ${key} IN #{item} - - - - + - AND ${key} = #{value} @@ -264,23 +272,234 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ORDER BY id ASC - - - - - - - - - + + + insert into sheep_file + + bs_manage_tags, + ranch_id, + dr_ranch, + sheepfold_id, + sheepfold_name, + electronic_tags, + variety_id, + variety, + family, + name, + gender, + birthday, + day_age, + month_age, + parity, + birth_weight, + weaning_date, + status_id, + weaning_weight, + current_weight, + weaning_day_age, + weaning_daily_gain, + breed_status_id, + breed, + bs_father_id, + father_manage_tags, + bs_mother_id, + mother_manage_tags, + receptor_id, + receptor_manage_tags, + father_father_id, + grandfather_manage_tags, + father_mother_id, + grandmother_manage_tags, + father_id, + maternal_grandfather_manage_tags, + mother_id, + maternal_grandmother_manage_tags, + mating_date, + mating_type_id, + preg_date, + lambing_date, + lambing_day, + mating_day, + gestation_day, + expected_date, + post_lambing_day, + lactation_day, + anestrous_day, + mating_counts, + mating_total, + miscarriage_counts, + comment, + controlled, + body, + breast, + source, + source_date, + source_ranch_id, + source_ranch, + create_by, + create_time, + update_by, + update_time, + is_delete, + + + #{bsManageTags}, + #{ranchId}, + #{drRanch}, + #{sheepfoldId}, + #{sheepfoldName}, + #{electronicTags}, + #{varietyId}, + #{variety}, + #{family}, + #{name}, + #{gender}, + #{birthday}, + #{dayAge}, + #{monthAge}, + #{parity}, + #{birthWeight}, + #{weaningDate}, + #{statusId}, + #{weaningWeight}, + #{currentWeight}, + #{weaningDayAge}, + #{weaningDailyGain}, + #{breedStatusId}, + #{breed}, + #{bsFatherId}, + #{fatherManageTags}, + #{bsMotherId}, + #{motherManageTags}, + #{receptorId}, + #{receptorManageTags}, + #{fatherFatherId}, + #{grandfatherManageTags}, + #{fatherMotherId}, + #{grandmotherManageTags}, + #{fatherId}, + #{maternalGrandfatherManageTags}, + #{motherId}, + #{maternalGrandmotherManageTags}, + #{matingDate}, + #{matingTypeId}, + #{pregDate}, + #{lambingDate}, + #{lambingDay}, + #{matingDay}, + #{gestationDay}, + #{expectedDate}, + #{postLambingDay}, + #{lactationDay}, + #{anestrousDay}, + #{matingCounts}, + #{matingTotal}, + #{miscarriageCounts}, + #{comment}, + #{controlled}, + #{body}, + #{breast}, + #{source}, + #{sourceDate}, + #{sourceRanchId}, + #{sourceRanch}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{isDelete}, + + + + + update sheep_file + + bs_manage_tags = #{bsManageTags}, + ranch_id = #{ranchId}, + dr_ranch = #{drRanch}, + sheepfold_id = #{sheepfoldId}, + sheepfold_name = #{sheepfoldName}, + electronic_tags = #{electronicTags}, + variety_id = #{varietyId}, + variety = #{variety}, + family = #{family}, + name = #{name}, + gender = #{gender}, + birthday = #{birthday}, + day_age = #{dayAge}, + month_age = #{monthAge}, + parity = #{parity}, + birth_weight = #{birthWeight}, + weaning_date = #{weaningDate}, + status_id = #{statusId}, + weaning_weight = #{weaningWeight}, + current_weight = #{currentWeight}, + weaning_day_age = #{weaningDayAge}, + weaning_daily_gain = #{weaningDailyGain}, + breed_status_id = #{breedStatusId}, + breed = #{breed}, + bs_father_id = #{bsFatherId}, + father_manage_tags = #{fatherManageTags}, + bs_mother_id = #{bsMotherId}, + mother_manage_tags = #{motherManageTags}, + receptor_id = #{receptorId}, + receptor_manage_tags = #{receptorManageTags}, + father_father_id = #{fatherFatherId}, + grandfather_manage_tags = #{grandfatherManageTags}, + father_mother_id = #{fatherMotherId}, + grandmother_manage_tags = #{grandmotherManageTags}, + father_id = #{fatherId}, + maternal_grandfather_manage_tags = #{maternalGrandfatherManageTags}, + mother_id = #{motherId}, + maternal_grandmother_manage_tags = #{maternalGrandmotherManageTags}, + mating_date = #{matingDate}, + mating_type_id = #{matingTypeId}, + preg_date = #{pregDate}, + lambing_date = #{lambingDate}, + lambing_day = #{lambingDay}, + mating_day = #{matingDay}, + gestation_day = #{gestationDay}, + expected_date = #{expectedDate}, + post_lambing_day = #{postLambingDay}, + lactation_day = #{lactationDay}, + anestrous_day = #{anestrousDay}, + mating_counts = #{matingCounts}, + mating_total = #{matingTotal}, + miscarriage_counts = #{miscarriageCounts}, + comment = #{comment}, + controlled = #{controlled}, + body = #{body}, + breast = #{breast}, + source = #{source}, + source_date = #{sourceDate}, + source_ranch_id = #{sourceRanchId}, + source_ranch = #{sourceRanch}, + update_by = #{updateBy}, + update_time = #{updateTime}, + is_delete = #{isDelete}, + + where id = #{id} + + + + update sheep_file set is_delete = 1 where id = #{id} + + + + update sheep_file set is_delete = 1 where id in + + #{id} + + + \ No newline at end of file From 6e575fdd218b10d169e51a1f693d55f6082dc158 Mon Sep 17 00:00:00 2001 From: wyt <414651037@qq.com> Date: Thu, 5 Feb 2026 14:17:34 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BE=8A=E8=88=8D?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=8C=89=E7=85=A7?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E5=AF=BC=E5=87=BA=E8=A1=A8=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SheepPedigreeController.java | 110 ++ .../module/base/domain/SheepPedigree.java | 996 ++++++++++++++++++ .../base/mapper/SheepPedigreeMapper.java | 70 ++ .../base/service/ISheepPedigreeService.java | 63 ++ .../impl/SheepPedigreeServiceImpl.java | 104 ++ .../base/util/SheepPedigreeExcelUtils.java | 511 +++++++++ .../mapper/base/SheepPedigreeMapper.xml | 391 +++++++ 7 files changed, 2245 insertions(+) create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/controller/SheepPedigreeController.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/domain/SheepPedigree.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/mapper/SheepPedigreeMapper.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/service/ISheepPedigreeService.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/service/impl/SheepPedigreeServiceImpl.java create mode 100644 zhyc-module/src/main/java/com/zhyc/module/base/util/SheepPedigreeExcelUtils.java create mode 100644 zhyc-module/src/main/resources/mapper/base/SheepPedigreeMapper.xml diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/controller/SheepPedigreeController.java b/zhyc-module/src/main/java/com/zhyc/module/base/controller/SheepPedigreeController.java new file mode 100644 index 0000000..7c655ad --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/controller/SheepPedigreeController.java @@ -0,0 +1,110 @@ +package com.zhyc.module.base.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import com.zhyc.module.base.util.SheepPedigreeExcelUtils; +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.SheepPedigree; +import com.zhyc.module.base.service.ISheepPedigreeService; +import com.zhyc.common.utils.poi.ExcelUtil; +import com.zhyc.common.core.page.TableDataInfo; + +/** + * VIEWController + * + * @author ruoyi + * @date 2026-02-04 + */ +@RestController +@RequestMapping("/system/pedigree") +public class SheepPedigreeController extends BaseController +{ + @Autowired + private ISheepPedigreeService sheepPedigreeService; + + + /** + * 查询VIEW列表 + */ + @PreAuthorize("@ss.hasPermi('system:pedigree:list')") + @GetMapping("/list") + public TableDataInfo list(SheepPedigree sheepPedigree) + { + startPage(); + List list = sheepPedigreeService.selectSheepPedigreeList(sheepPedigree); + return getDataTable(list); + } + + /** + * 导出VIEW列表 + */ + + // 在Controller/Service中注入工具类 + @Autowired + private SheepPedigreeExcelUtils sheepPedigreeExcelUtils; + @PreAuthorize("@ss.hasPermi('system:pedigree:export')") + @Log(title = "VIEW", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, SheepPedigree sheepPedigree) throws Exception { + List dataList = sheepPedigreeService.selectSheepPedigreeList(sheepPedigree); + // 调用实例方法(而非静态方法) + sheepPedigreeExcelUtils.export(response, dataList); + } + + /** + * 获取VIEW详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:pedigree:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(sheepPedigreeService.selectSheepPedigreeById(id)); + } + + /** + * 新增VIEW + */ + @PreAuthorize("@ss.hasPermi('system:pedigree:add')") + @Log(title = "VIEW", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody SheepPedigree sheepPedigree) + { + return toAjax(sheepPedigreeService.insertSheepPedigree(sheepPedigree)); + } + + /** + * 修改VIEW + */ + @PreAuthorize("@ss.hasPermi('system:pedigree:edit')") + @Log(title = "VIEW", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody SheepPedigree sheepPedigree) + { + return toAjax(sheepPedigreeService.updateSheepPedigree(sheepPedigree)); + } + + /** + * 删除VIEW + */ + @PreAuthorize("@ss.hasPermi('system:pedigree:remove')") + @Log(title = "VIEW", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(sheepPedigreeService.deleteSheepPedigreeByIds(ids)); + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/domain/SheepPedigree.java b/zhyc-module/src/main/java/com/zhyc/module/base/domain/SheepPedigree.java new file mode 100644 index 0000000..6615df8 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/domain/SheepPedigree.java @@ -0,0 +1,996 @@ +package com.zhyc.module.base.domain; + +import java.math.BigDecimal; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +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; + +/** + * VIEW对象 sheep_pedigree + * + * @author ruoyi + * @date 2026-02-04 + */ +public class SheepPedigree extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Long id; + + /** 管理耳号 */ + @Excel(name = "管理耳号") + private String bsManageTags; + + /** 牧场id */ + @Excel(name = "牧场id") + private Long ranchId; + + /** $column.columnComment */ + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") + private String drRanch; + + /** 羊舍id */ + @Excel(name = "羊舍id") + private Long sheepfoldId; + + /** 羊舍名称 */ + @Excel(name = "羊舍名称") + private String sheepfoldName; + + /** 电子耳号 */ + @Excel(name = "电子耳号") + private String electronicTags; + + /** 品种id */ + @Excel(name = "品种id") + private Long varietyId; + + /** 品种 */ + @Excel(name = "品种") + private String variety; + + /** 家系 */ + @Excel(name = "家系") + private String family; + + /** 羊只类型 */ + @Excel(name = "羊只类型") + private String name; + + /** 性别 */ + @Excel(name = "性别") + private Long gender; + + /** 出生日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "出生日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date birthday; + + /** $column.columnComment */ + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") + private Long dayAge; + + /** $column.columnComment */ + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") + private Long monthAge; + + /** 胎次 */ + @Excel(name = "胎次") + private Long parity; + + /** 出生体重 */ + @Excel(name = "出生体重") + private Long birthWeight; + + /** 断奶日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "断奶日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date weaningDate; + + /** 羊只状态 */ + @Excel(name = "羊只状态") + private Long statusId; + + /** 断奶体重 */ + @Excel(name = "断奶体重") + private Long weaningWeight; + + /** $column.columnComment */ + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") + private Long weaningDayAge; + + /** $column.columnComment */ + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") + private BigDecimal weaningDailyGain; + + /** 当前体重 */ + @Excel(name = "当前体重") + private Long currentWeight; + + /** 繁育状态id */ + @Excel(name = "繁育状态id") + private Long breedStatusId; + + /** 繁殖状态 */ + @Excel(name = "繁殖状态") + private String breed; + + /** 父号id */ + @Excel(name = "父号id") + private Long bsFatherId; + + /** 管理耳号 */ + @Excel(name = "管理耳号") + private String fatherManageTags; + + /** 母号id */ + @Excel(name = "母号id") + private Long bsMotherId; + + /** 管理耳号 */ + @Excel(name = "管理耳号") + private String motherManageTags; + + /** 受体id */ + @Excel(name = "受体id") + private Long receptorId; + + /** 管理耳号 */ + @Excel(name = "管理耳号") + private String receptorManageTags; + + /** 父号id */ + @Excel(name = "父号id") + private Long fatherFatherId; + + /** 管理耳号 */ + @Excel(name = "祖父管理耳号") + private String grandfatherManageTags; + + /** 母号id */ + @Excel(name = "母号id") + private Long fatherMotherId; + + /** 管理耳号 */ + @Excel(name = "祖母管理耳号") + private String grandmotherManageTags; + + /** 父号id */ + @Excel(name = "父号id") + private Long fatherId; + + /** 管理耳号 */ + @Excel(name = "管理耳号") + private String maternalGrandfatherManageTags; + + /** 母号id */ + @Excel(name = "母号id") + private Long motherId; + + /** 管理耳号 */ + @Excel(name = "管理耳号") + private String maternalGrandmotherManageTags; + + /** 配种日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "配种日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date matingDate; + + /** 配种类型 */ + @Excel(name = "配种类型") + private Long matingTypeId; + + /** 孕检日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "孕检日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date pregDate; + + /** 产羔日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "产羔日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date lambingDate; + + /** 产羔时怀孕天数 */ + @Excel(name = "产羔时怀孕天数") + private Long lambingDay; + + /** $column.columnComment */ + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") + private Long matingDay; + + /** 怀孕天数 */ + @Excel(name = "怀孕天数") + private Long gestationDay; + + /** 预产日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "预产日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date expectedDate; + + /** 产后天数 */ + @Excel(name = "产后天数") + private Long postLambingDay; + + /** 泌乳天数 */ + @Excel(name = "泌乳天数") + private Long lactationDay; + + /** 空怀天数 */ + @Excel(name = "空怀天数") + private Long anestrousDay; + + /** 配种次数 */ + @Excel(name = "配种次数") + private Long matingCounts; + + /** $column.columnComment */ + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") + private Long matingTotal; + + /** 累计流产次数 */ + @Excel(name = "累计流产次数") + private Long miscarriageCounts; + + /** 备注 */ + @Excel(name = "备注") + private String comment; + + /** 是否性控 */ + @Excel(name = "是否性控") + private Long controlled; + + /** 体况评分 */ + @Excel(name = "体况评分") + private Long body; + + /** 乳房评分 */ + @Excel(name = "乳房评分") + private Long breast; + + /** 入群来源 */ + @Excel(name = "入群来源") + private String source; + + /** 入群日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "入群日期", width = 30, dateFormat = "yyyy-MM-dd") + private Date sourceDate; + + /** 来源牧场id */ + @Excel(name = "来源牧场id") + private Long sourceRanchId; + + /** $column.columnComment */ + @Excel(name = "来源牧场", readConverterExp = "$column.readConverterExp()") + private String sourceRanch; + + /** 是否删除 */ + @Excel(name = "是否删除") + private Long isDelete; + + /** $column.columnComment */ + @Excel(name = "毛色", readConverterExp = "$column.readConverterExp()") + private String sheepColor; + + /** $column.columnComment */ + @Excel(name = "等级", readConverterExp = "$column.readConverterExp()") + private String groupName; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setBsManageTags(String bsManageTags) + { + this.bsManageTags = bsManageTags; + } + + public String getBsManageTags() + { + return bsManageTags; + } + + public void setRanchId(Long ranchId) + { + this.ranchId = ranchId; + } + + public Long getRanchId() + { + return ranchId; + } + + public void setDrRanch(String drRanch) + { + this.drRanch = drRanch; + } + + public String getDrRanch() + { + return drRanch; + } + + public void setSheepfoldId(Long sheepfoldId) + { + this.sheepfoldId = sheepfoldId; + } + + public Long getSheepfoldId() + { + return sheepfoldId; + } + + public void setSheepfoldName(String sheepfoldName) + { + this.sheepfoldName = sheepfoldName; + } + + public String getSheepfoldName() + { + return sheepfoldName; + } + + public void setElectronicTags(String electronicTags) + { + this.electronicTags = electronicTags; + } + + public String getElectronicTags() + { + return electronicTags; + } + + public void setVarietyId(Long varietyId) + { + this.varietyId = varietyId; + } + + public Long getVarietyId() + { + return varietyId; + } + + public void setVariety(String variety) + { + this.variety = variety; + } + + public String getVariety() + { + return variety; + } + + public void setFamily(String family) + { + this.family = family; + } + + public String getFamily() + { + return family; + } + + public void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + + public void setGender(Long gender) + { + this.gender = gender; + } + + public Long getGender() + { + return gender; + } + + public void setBirthday(Date birthday) + { + this.birthday = birthday; + } + + public Date getBirthday() + { + return birthday; + } + + public void setDayAge(Long dayAge) + { + this.dayAge = dayAge; + } + + public Long getDayAge() + { + return dayAge; + } + + public void setMonthAge(Long monthAge) + { + this.monthAge = monthAge; + } + + public Long getMonthAge() + { + return monthAge; + } + + public void setParity(Long parity) + { + this.parity = parity; + } + + public Long getParity() + { + return parity; + } + + public void setBirthWeight(Long birthWeight) + { + this.birthWeight = birthWeight; + } + + public Long getBirthWeight() + { + return birthWeight; + } + + public void setWeaningDate(Date weaningDate) + { + this.weaningDate = weaningDate; + } + + public Date getWeaningDate() + { + return weaningDate; + } + + public void setStatusId(Long statusId) + { + this.statusId = statusId; + } + + public Long getStatusId() + { + return statusId; + } + + public void setWeaningWeight(Long weaningWeight) + { + this.weaningWeight = weaningWeight; + } + + public Long getWeaningWeight() + { + return weaningWeight; + } + + public void setWeaningDayAge(Long weaningDayAge) + { + this.weaningDayAge = weaningDayAge; + } + + public Long getWeaningDayAge() + { + return weaningDayAge; + } + + public void setWeaningDailyGain(BigDecimal weaningDailyGain) + { + this.weaningDailyGain = weaningDailyGain; + } + + public BigDecimal getWeaningDailyGain() + { + return weaningDailyGain; + } + + public void setCurrentWeight(Long currentWeight) + { + this.currentWeight = currentWeight; + } + + public Long getCurrentWeight() + { + return currentWeight; + } + + public void setBreedStatusId(Long breedStatusId) + { + this.breedStatusId = breedStatusId; + } + + public Long getBreedStatusId() + { + return breedStatusId; + } + + public void setBreed(String breed) + { + this.breed = breed; + } + + public String getBreed() + { + return breed; + } + + public void setBsFatherId(Long bsFatherId) + { + this.bsFatherId = bsFatherId; + } + + public Long getBsFatherId() + { + return bsFatherId; + } + + public void setFatherManageTags(String fatherManageTags) + { + this.fatherManageTags = fatherManageTags; + } + + public String getFatherManageTags() + { + return fatherManageTags; + } + + public void setBsMotherId(Long bsMotherId) + { + this.bsMotherId = bsMotherId; + } + + public Long getBsMotherId() + { + return bsMotherId; + } + + public void setMotherManageTags(String motherManageTags) + { + this.motherManageTags = motherManageTags; + } + + public String getMotherManageTags() + { + return motherManageTags; + } + + public void setReceptorId(Long receptorId) + { + this.receptorId = receptorId; + } + + public Long getReceptorId() + { + return receptorId; + } + + public void setReceptorManageTags(String receptorManageTags) + { + this.receptorManageTags = receptorManageTags; + } + + public String getReceptorManageTags() + { + return receptorManageTags; + } + + public void setFatherFatherId(Long fatherFatherId) + { + this.fatherFatherId = fatherFatherId; + } + + public Long getFatherFatherId() + { + return fatherFatherId; + } + + public void setGrandfatherManageTags(String grandfatherManageTags) + { + this.grandfatherManageTags = grandfatherManageTags; + } + + public String getGrandfatherManageTags() + { + return grandfatherManageTags; + } + + public void setFatherMotherId(Long fatherMotherId) + { + this.fatherMotherId = fatherMotherId; + } + + public Long getFatherMotherId() + { + return fatherMotherId; + } + + public void setGrandmotherManageTags(String grandmotherManageTags) + { + this.grandmotherManageTags = grandmotherManageTags; + } + + public String getGrandmotherManageTags() + { + return grandmotherManageTags; + } + + public void setFatherId(Long fatherId) + { + this.fatherId = fatherId; + } + + public Long getFatherId() + { + return fatherId; + } + + public void setMaternalGrandfatherManageTags(String maternalGrandfatherManageTags) + { + this.maternalGrandfatherManageTags = maternalGrandfatherManageTags; + } + + public String getMaternalGrandfatherManageTags() + { + return maternalGrandfatherManageTags; + } + + public void setMotherId(Long motherId) + { + this.motherId = motherId; + } + + public Long getMotherId() + { + return motherId; + } + + public void setMaternalGrandmotherManageTags(String maternalGrandmotherManageTags) + { + this.maternalGrandmotherManageTags = maternalGrandmotherManageTags; + } + + public String getMaternalGrandmotherManageTags() + { + return maternalGrandmotherManageTags; + } + + public void setMatingDate(Date matingDate) + { + this.matingDate = matingDate; + } + + public Date getMatingDate() + { + return matingDate; + } + + public void setMatingTypeId(Long matingTypeId) + { + this.matingTypeId = matingTypeId; + } + + public Long getMatingTypeId() + { + return matingTypeId; + } + + public void setPregDate(Date pregDate) + { + this.pregDate = pregDate; + } + + public Date getPregDate() + { + return pregDate; + } + + public void setLambingDate(Date lambingDate) + { + this.lambingDate = lambingDate; + } + + public Date getLambingDate() + { + return lambingDate; + } + + public void setLambingDay(Long lambingDay) + { + this.lambingDay = lambingDay; + } + + public Long getLambingDay() + { + return lambingDay; + } + + public void setMatingDay(Long matingDay) + { + this.matingDay = matingDay; + } + + public Long getMatingDay() + { + return matingDay; + } + + public void setGestationDay(Long gestationDay) + { + this.gestationDay = gestationDay; + } + + public Long getGestationDay() + { + return gestationDay; + } + + public void setExpectedDate(Date expectedDate) + { + this.expectedDate = expectedDate; + } + + public Date getExpectedDate() + { + return expectedDate; + } + + public void setPostLambingDay(Long postLambingDay) + { + this.postLambingDay = postLambingDay; + } + + public Long getPostLambingDay() + { + return postLambingDay; + } + + public void setLactationDay(Long lactationDay) + { + this.lactationDay = lactationDay; + } + + public Long getLactationDay() + { + return lactationDay; + } + + public void setAnestrousDay(Long anestrousDay) + { + this.anestrousDay = anestrousDay; + } + + public Long getAnestrousDay() + { + return anestrousDay; + } + + public void setMatingCounts(Long matingCounts) + { + this.matingCounts = matingCounts; + } + + public Long getMatingCounts() + { + return matingCounts; + } + + public void setMatingTotal(Long matingTotal) + { + this.matingTotal = matingTotal; + } + + public Long getMatingTotal() + { + return matingTotal; + } + + public void setMiscarriageCounts(Long miscarriageCounts) + { + this.miscarriageCounts = miscarriageCounts; + } + + public Long getMiscarriageCounts() + { + return miscarriageCounts; + } + + public void setComment(String comment) + { + this.comment = comment; + } + + public String getComment() + { + return comment; + } + + public void setControlled(Long controlled) + { + this.controlled = controlled; + } + + public Long getControlled() + { + return controlled; + } + + public void setBody(Long body) + { + this.body = body; + } + + public Long getBody() + { + return body; + } + + public void setBreast(Long breast) + { + this.breast = breast; + } + + public Long getBreast() + { + return breast; + } + + public void setSource(String source) + { + this.source = source; + } + + public String getSource() + { + return source; + } + + public void setSourceDate(Date sourceDate) + { + this.sourceDate = sourceDate; + } + + public Date getSourceDate() + { + return sourceDate; + } + + public void setSourceRanchId(Long sourceRanchId) + { + this.sourceRanchId = sourceRanchId; + } + + public Long getSourceRanchId() + { + return sourceRanchId; + } + + public void setSourceRanch(String sourceRanch) + { + this.sourceRanch = sourceRanch; + } + + public String getSourceRanch() + { + return sourceRanch; + } + + public void setIsDelete(Long isDelete) + { + this.isDelete = isDelete; + } + + public Long getIsDelete() + { + return isDelete; + } + + public void setSheepColor(String sheepColor) + { + this.sheepColor = sheepColor; + } + + public String getSheepColor() + { + return sheepColor; + } + + public void setGroupName(String groupName) + { + this.groupName = groupName; + } + + public String getGroupName() + { + return groupName; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("bsManageTags", getBsManageTags()) + .append("ranchId", getRanchId()) + .append("drRanch", getDrRanch()) + .append("sheepfoldId", getSheepfoldId()) + .append("sheepfoldName", getSheepfoldName()) + .append("electronicTags", getElectronicTags()) + .append("varietyId", getVarietyId()) + .append("variety", getVariety()) + .append("family", getFamily()) + .append("name", getName()) + .append("gender", getGender()) + .append("birthday", getBirthday()) + .append("dayAge", getDayAge()) + .append("monthAge", getMonthAge()) + .append("parity", getParity()) + .append("birthWeight", getBirthWeight()) + .append("weaningDate", getWeaningDate()) + .append("statusId", getStatusId()) + .append("weaningWeight", getWeaningWeight()) + .append("weaningDayAge", getWeaningDayAge()) + .append("weaningDailyGain", getWeaningDailyGain()) + .append("currentWeight", getCurrentWeight()) + .append("breedStatusId", getBreedStatusId()) + .append("breed", getBreed()) + .append("bsFatherId", getBsFatherId()) + .append("fatherManageTags", getFatherManageTags()) + .append("bsMotherId", getBsMotherId()) + .append("motherManageTags", getMotherManageTags()) + .append("receptorId", getReceptorId()) + .append("receptorManageTags", getReceptorManageTags()) + .append("fatherFatherId", getFatherFatherId()) + .append("grandfatherManageTags", getGrandfatherManageTags()) + .append("fatherMotherId", getFatherMotherId()) + .append("grandmotherManageTags", getGrandmotherManageTags()) + .append("fatherId", getFatherId()) + .append("maternalGrandfatherManageTags", getMaternalGrandfatherManageTags()) + .append("motherId", getMotherId()) + .append("maternalGrandmotherManageTags", getMaternalGrandmotherManageTags()) + .append("matingDate", getMatingDate()) + .append("matingTypeId", getMatingTypeId()) + .append("pregDate", getPregDate()) + .append("lambingDate", getLambingDate()) + .append("lambingDay", getLambingDay()) + .append("matingDay", getMatingDay()) + .append("gestationDay", getGestationDay()) + .append("expectedDate", getExpectedDate()) + .append("postLambingDay", getPostLambingDay()) + .append("lactationDay", getLactationDay()) + .append("anestrousDay", getAnestrousDay()) + .append("matingCounts", getMatingCounts()) + .append("matingTotal", getMatingTotal()) + .append("miscarriageCounts", getMiscarriageCounts()) + .append("comment", getComment()) + .append("controlled", getControlled()) + .append("body", getBody()) + .append("breast", getBreast()) + .append("source", getSource()) + .append("sourceDate", getSourceDate()) + .append("sourceRanchId", getSourceRanchId()) + .append("sourceRanch", getSourceRanch()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("isDelete", getIsDelete()) + .append("sheepColor", getSheepColor()) + .append("groupName", getGroupName()) + .toString(); + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/mapper/SheepPedigreeMapper.java b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/SheepPedigreeMapper.java new file mode 100644 index 0000000..4abdf72 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/mapper/SheepPedigreeMapper.java @@ -0,0 +1,70 @@ +package com.zhyc.module.base.mapper; + +import java.util.List; +import com.zhyc.module.base.domain.SheepPedigree; +import org.apache.ibatis.annotations.Param; + +/** + * VIEWMapper接口 + * + * @author ruoyi + * @date 2026-02-04 + */ +public interface SheepPedigreeMapper +{ + /** + * 查询VIEW + * + * @param id VIEW主键 + * @return VIEW + */ + public SheepPedigree selectSheepPedigreeById(Long id); + + /** + * 查询VIEW列表 + * + * @param sheepPedigree VIEW + * @return VIEW集合 + */ + public List selectSheepPedigreeList(SheepPedigree sheepPedigree); + + /** + * 新增VIEW + * + * @param sheepPedigree VIEW + * @return 结果 + */ + public int insertSheepPedigree(SheepPedigree sheepPedigree); + + /** + * 修改VIEW + * + * @param sheepPedigree VIEW + * @return 结果 + */ + public int updateSheepPedigree(SheepPedigree sheepPedigree); + + /** + * 删除VIEW + * + * @param id VIEW主键 + * @return 结果 + */ + public int deleteSheepPedigreeById(Long id); + + /** + * 批量删除VIEW + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteSheepPedigreeByIds(Long[] ids); + + + /** + * 根据int类型id查询繁育状态名称 + * @param id 主键id(int类型) + * @return 繁育状态名称(breed列的值) + */ + String selectBreedNameById(@Param("id") Long id); +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/ISheepPedigreeService.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/ISheepPedigreeService.java new file mode 100644 index 0000000..47387b1 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/ISheepPedigreeService.java @@ -0,0 +1,63 @@ +package com.zhyc.module.base.service; + +import java.util.List; +import com.zhyc.module.base.domain.SheepPedigree; + +/** + * VIEWService接口 + * + * @author ruoyi + * @date 2026-02-04 + */ +public interface ISheepPedigreeService +{ + /** + * 查询VIEW + * + * @param id VIEW主键 + * @return VIEW + */ + public SheepPedigree selectSheepPedigreeById(Long id); + + /** + * 查询VIEW列表 + * + * @param sheepPedigree VIEW + * @return VIEW集合 + */ + public List selectSheepPedigreeList(SheepPedigree sheepPedigree); + + /** + * 新增VIEW + * + * @param sheepPedigree VIEW + * @return 结果 + */ + public int insertSheepPedigree(SheepPedigree sheepPedigree); + + /** + * 修改VIEW + * + * @param sheepPedigree VIEW + * @return 结果 + */ + public int updateSheepPedigree(SheepPedigree sheepPedigree); + + /** + * 批量删除VIEW + * + * @param ids 需要删除的VIEW主键集合 + * @return 结果 + */ + public int deleteSheepPedigreeByIds(Long[] ids); + + /** + * 删除VIEW信息 + * + * @param id VIEW主键 + * @return 结果 + */ + public int deleteSheepPedigreeById(Long id); + + public String getBreedNameById(Long id); +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/SheepPedigreeServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/SheepPedigreeServiceImpl.java new file mode 100644 index 0000000..9b03073 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/service/impl/SheepPedigreeServiceImpl.java @@ -0,0 +1,104 @@ +package com.zhyc.module.base.service.impl; + +import java.util.List; +import com.zhyc.common.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.zhyc.module.base.mapper.SheepPedigreeMapper; +import com.zhyc.module.base.domain.SheepPedigree; +import com.zhyc.module.base.service.ISheepPedigreeService; + +/** + * VIEWService业务层处理 + * + * @author ruoyi + * @date 2026-02-04 + */ +@Service +public class SheepPedigreeServiceImpl implements ISheepPedigreeService +{ + @Autowired + private SheepPedigreeMapper sheepPedigreeMapper; + + /** + * 查询VIEW + * + * @param id VIEW主键 + * @return VIEW + */ + @Override + public SheepPedigree selectSheepPedigreeById(Long id) + { + return sheepPedigreeMapper.selectSheepPedigreeById(id); + } + + /** + * 查询VIEW列表 + * + * @param sheepPedigree VIEW + * @return VIEW + */ + @Override + public List selectSheepPedigreeList(SheepPedigree sheepPedigree) + { + return sheepPedigreeMapper.selectSheepPedigreeList(sheepPedigree); + } + + /** + * 新增VIEW + * + * @param sheepPedigree VIEW + * @return 结果 + */ + @Override + public int insertSheepPedigree(SheepPedigree sheepPedigree) + { + sheepPedigree.setCreateTime(DateUtils.getNowDate()); + return sheepPedigreeMapper.insertSheepPedigree(sheepPedigree); + } + + /** + * 修改VIEW + * + * @param sheepPedigree VIEW + * @return 结果 + */ + @Override + public int updateSheepPedigree(SheepPedigree sheepPedigree) + { + sheepPedigree.setUpdateTime(DateUtils.getNowDate()); + return sheepPedigreeMapper.updateSheepPedigree(sheepPedigree); + } + + /** + * 批量删除VIEW + * + * @param ids 需要删除的VIEW主键 + * @return 结果 + */ + @Override + public int deleteSheepPedigreeByIds(Long[] ids) + { + return sheepPedigreeMapper.deleteSheepPedigreeByIds(ids); + } + + /** + * 删除VIEW信息 + * + * @param id VIEW主键 + * @return 结果 + */ + @Override + public int deleteSheepPedigreeById(Long id) + { + return sheepPedigreeMapper.deleteSheepPedigreeById(id); + } + + @Override + public String getBreedNameById(Long id) { + if (id == null) { // int类型id为空直接返回空 + return ""; + } + return sheepPedigreeMapper.selectBreedNameById(id); + } +} diff --git a/zhyc-module/src/main/java/com/zhyc/module/base/util/SheepPedigreeExcelUtils.java b/zhyc-module/src/main/java/com/zhyc/module/base/util/SheepPedigreeExcelUtils.java new file mode 100644 index 0000000..bc148b7 --- /dev/null +++ b/zhyc-module/src/main/java/com/zhyc/module/base/util/SheepPedigreeExcelUtils.java @@ -0,0 +1,511 @@ +package com.zhyc.module.base.util; + +import com.zhyc.module.base.domain.SheepPedigree; +import com.zhyc.module.base.service.ISheepPedigreeService; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import javax.servlet.http.HttpServletResponse; +import java.io.OutputStream; +import java.net.URLEncoder; +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import com.zhyc.common.utils.DictUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 羊只系谱自定义Excel导出工具(适配羊只系谱表(2)样式) + */ +@Component +public class SheepPedigreeExcelUtils { + // 日期格式化 + private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); + + // 注入Service接口 + @Autowired + private ISheepPedigreeService sheepPedigreeService; + + /** + * 导出指定bsManageTags的羊只系谱(符合羊只系谱表(2)样式) + */ + public void export(HttpServletResponse response, List dataList) throws Exception { + // 1. 创建Excel工作簿和工作表 + Workbook workbook = new XSSFWorkbook(); + Sheet sheet = workbook.createSheet("羊只系谱"); + // 设置列宽(6列,索引0-5) + sheet.setColumnWidth(0, 15 * 256); // 第1列 + sheet.setColumnWidth(1, 15 * 256); // 第2列 + sheet.setColumnWidth(2, 15 * 256); // 第3列 + sheet.setColumnWidth(3, 15 * 256); // 第4列 + sheet.setColumnWidth(4, 15 * 256); // 第5列 + sheet.setColumnWidth(5, 15 * 256); // 第6列 + + // 2. 定义样式(新增:通用边框样式,所有单元格都应用) + CellStyle titleStyle = createTitleStyle(workbook); + CellStyle blockTitleStyle = createBlockTitleStyle(workbook); + CellStyle contentStyle = createContentStyle(workbook); + CellStyle borderStyle = createBorderStyle(workbook); // 纯边框样式,用于空单元格 + + int rowNum = 0; + // 遍历数据 + for (SheepPedigree pedigree : dataList) { + // ========== 1. 大标题:羊只系谱 ========== + Row titleRow = sheet.createRow(rowNum++); + titleRow.setHeightInPoints(25); + Cell titleCell = titleRow.createCell(0); + titleCell.setCellValue("羊只系谱"); + titleCell.setCellStyle(titleStyle); + // 给标题行所有列应用边框 + fillRowWithBorder(titleRow, 0, 5, borderStyle); + sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 0, 5)); + + // ========== 2. 基础信息区块 ========== + // 普通耳号 + Row earTagRow = sheet.createRow(rowNum++); + earTagRow.setHeightInPoints(20); + Cell earTagLabelCell = earTagRow.createCell(0); + earTagLabelCell.setCellValue("普通耳号"); + earTagLabelCell.setCellStyle(contentStyle); + + String earTagContent = pedigree.getBsManageTags() != null ? pedigree.getBsManageTags() : ""; + Cell earTagValueCell = earTagRow.createCell(1); + earTagValueCell.setCellValue(earTagContent); + earTagValueCell.setCellStyle(contentStyle); + + // 给当前行所有列填充边框 + fillRowWithBorder(earTagRow, 0, 5, borderStyle); + CellRangeAddress earTagMerge = new CellRangeAddress( + rowNum - 1, + rowNum - 1, + 1, + 5 + ); + sheet.addMergedRegion(earTagMerge); + + // 品种 + 类别 + Row varietyRow = sheet.createRow(rowNum++); + varietyRow.setHeightInPoints(20); + Cell varietyLabelCell = varietyRow.createCell(0); + varietyLabelCell.setCellValue("品种"); + varietyLabelCell.setCellStyle(contentStyle); + + String varietyContent = pedigree.getVariety() != null ? pedigree.getVariety() : ""; + Cell varietyValueCell = varietyRow.createCell(1); + varietyValueCell.setCellValue(varietyContent); + varietyValueCell.setCellStyle(contentStyle); + + Cell categoryLabelCell = varietyRow.createCell(2); + categoryLabelCell.setCellValue("类别"); + categoryLabelCell.setCellStyle(contentStyle); + + String categoryContent = pedigree.getName() != null ? pedigree.getName() : ""; + Cell categoryValueCell = varietyRow.createCell(3); + categoryValueCell.setCellValue(categoryContent); + categoryValueCell.setCellStyle(contentStyle); + + // 填充边框 + fillRowWithBorder(varietyRow, 0, 5, borderStyle); + CellRangeAddress categoryMerge = new CellRangeAddress( + rowNum - 1, + rowNum - 1, + 3, + 5 + ); + sheet.addMergedRegion(categoryMerge); + + // 性别 + 出生重量 + 出生日期 + Row genderRow = sheet.createRow(rowNum++); + genderRow.setHeightInPoints(20); + Cell genderLabelCell = genderRow.createCell(0); + genderLabelCell.setCellValue("性别"); + genderLabelCell.setCellStyle(contentStyle); + + Cell genderValueCell = genderRow.createCell(1); + genderValueCell.setCellValue(getGenderText(pedigree.getGender())); + genderValueCell.setCellStyle(contentStyle); + + Cell birthWeightLabelCell = genderRow.createCell(2); + birthWeightLabelCell.setCellValue("出生重量"); + birthWeightLabelCell.setCellStyle(contentStyle); + + Cell birthWeightValueCell = genderRow.createCell(3); + String birthWeightContent = pedigree.getBirthWeight() != null ? pedigree.getBirthWeight() + "kg" : ""; + birthWeightValueCell.setCellValue(birthWeightContent); + birthWeightValueCell.setCellStyle(contentStyle); + + Cell birthDateLabelCell = genderRow.createCell(4); + birthDateLabelCell.setCellValue("出生日期"); + birthDateLabelCell.setCellStyle(contentStyle); + + Cell birthDateValueCell = genderRow.createCell(5); + String birthDate = pedigree.getBirthday() != null ? DATE_FORMAT.format(pedigree.getBirthday()) : ""; + birthDateValueCell.setCellValue(birthDate); + birthDateValueCell.setCellStyle(contentStyle); + + // 填充边框 + fillRowWithBorder(genderRow, 0, 5, borderStyle); + + // 毛色 + 月龄 + 状态 + Row furColorRow = sheet.createRow(rowNum++); + furColorRow.setHeightInPoints(20); + Cell furColorLabelCell = furColorRow.createCell(0); + furColorLabelCell.setCellValue("毛色"); + furColorLabelCell.setCellStyle(contentStyle); + + Cell furColorValueCell = furColorRow.createCell(1); + String furColorContent = pedigree.getSheepColor() != null ? pedigree.getSheepColor() : ""; + furColorValueCell.setCellValue(furColorContent); + furColorValueCell.setCellStyle(contentStyle); + + Cell monthAgeLabelCell = furColorRow.createCell(2); + monthAgeLabelCell.setCellValue("月龄"); + monthAgeLabelCell.setCellStyle(contentStyle); + + Cell monthAgeValueCell = furColorRow.createCell(3); + String monthAgeContent = pedigree.getMonthAge() != null ? pedigree.getMonthAge() + "月" : ""; + monthAgeValueCell.setCellValue(monthAgeContent); + monthAgeValueCell.setCellStyle(contentStyle); + + Cell statusLabelCell = furColorRow.createCell(4); + statusLabelCell.setCellValue("状态"); + statusLabelCell.setCellStyle(contentStyle); + + Map statusDict = new HashMap<>(); + statusDict.put(1L, "在群"); + statusDict.put(2L, "不在群"); + statusDict.put(null, ""); + + Object statusId = pedigree.getStatusId(); + String statusContent = statusDict.getOrDefault(statusId, "未知状态"); + + Cell statusValueCell = furColorRow.createCell(5); + statusValueCell.setCellValue(statusContent); + statusValueCell.setCellStyle(contentStyle); + + // 填充边框 + fillRowWithBorder(furColorRow, 0, 5, borderStyle); + + // 繁育状态 + 来源 + Row breedStatusRow = sheet.createRow(rowNum++); + breedStatusRow.setHeightInPoints(20); + int currentRow = rowNum - 1; + + Cell breedStatusLabelCell = breedStatusRow.createCell(0); + breedStatusLabelCell.setCellValue("繁育状态"); + breedStatusLabelCell.setCellStyle(contentStyle); + + Cell breedStatusValueCell = breedStatusRow.createCell(1); + String breedStatusContent = ""; + try { + Object breedObj = pedigree.getBreed(); + if (breedObj != null) { + breedStatusContent = breedObj.toString().trim(); + } + if (breedStatusContent == null || breedStatusContent.isEmpty()) { + breedStatusContent = ""; + } + } catch (Exception e) { + breedStatusContent = ""; + } + breedStatusValueCell.setCellValue(breedStatusContent); + breedStatusValueCell.setCellStyle(contentStyle); + + Cell sourceLabelCell = breedStatusRow.createCell(2); + sourceLabelCell.setCellValue("来源"); + sourceLabelCell.setCellStyle(contentStyle); + + Cell sourceValueCell = breedStatusRow.createCell(3); + String sourceCode = pedigree.getSource() != null ? pedigree.getSource().toString() : ""; + String sourceContent = ""; + try { + sourceContent = DictUtils.getDictLabel("source", sourceCode, ""); + } catch (Exception e) { + sourceContent = ""; + System.err.println("来源字典映射失败:" + e.getMessage()); + } + sourceValueCell.setCellValue(sourceContent); + sourceValueCell.setCellStyle(contentStyle); + + // 填充边框 + fillRowWithBorder(breedStatusRow, 0, 5, borderStyle); + CellRangeAddress sourceMerge = new CellRangeAddress( + currentRow, + currentRow, + 3, + 5 + ); + sheet.addMergedRegion(sourceMerge); + + // 等级 + 家系 + Row levelRow = sheet.createRow(rowNum++); + levelRow.setHeightInPoints(20); + int currentLevelRow = rowNum - 1; + + Cell levelLabelCell = levelRow.createCell(0); + levelLabelCell.setCellValue("等级"); + levelLabelCell.setCellStyle(contentStyle); + + Cell levelValueCell = levelRow.createCell(1); + String levelContent = pedigree.getGroupName() != null ? pedigree.getGroupName() : ""; + levelValueCell.setCellValue(levelContent); + levelValueCell.setCellStyle(contentStyle); + + Cell familyLabelCell = levelRow.createCell(2); + familyLabelCell.setCellValue("家系"); + familyLabelCell.setCellStyle(contentStyle); + + Cell familyValueCell = levelRow.createCell(3); + String familyContent = pedigree.getFamily() != null ? pedigree.getFamily() : ""; + familyValueCell.setCellValue(familyContent); + familyValueCell.setCellStyle(contentStyle); + + // 填充边框 + fillRowWithBorder(levelRow, 0, 5, borderStyle); + CellRangeAddress familyMerge = new CellRangeAddress( + currentLevelRow, + currentLevelRow, + 3, + 5 + ); + sheet.addMergedRegion(familyMerge); + + // ========== 3. 系谱信息区块(最终修复版) ========== + Row pedigreeTitleRow = sheet.createRow(rowNum++); + pedigreeTitleRow.setHeightInPoints(25); // 区块标题行高 + Cell pedigreeTitleCell = pedigreeTitleRow.createCell(0); + pedigreeTitleCell.setCellValue("系谱信息"); + pedigreeTitleCell.setCellStyle(blockTitleStyle); + // 填充标题行边框 + fillRowWithBorder(pedigreeTitleRow, 0, 5, borderStyle); + sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 0, 5)); + + // 系谱区块起始行(此时rowNum是系谱内容第1行) + int pedigreeStartRow = rowNum; + int pedigreeTotalRows = 12; + // 统一设置系谱12行的行高+填充边框 + for (int i = 0; i < pedigreeTotalRows; i++) { + Row tempRow = sheet.createRow(pedigreeStartRow + i); + tempRow.setHeightInPoints(20); + // 给每行的0-5列都填充边框样式 + fillRowWithBorder(tempRow, 0, 5, borderStyle); + } + + // ========== 1. 羊只列:第1列合并12行 ========== + Row sheepRow = sheet.getRow(pedigreeStartRow); + Cell sheepCell = sheepRow.createCell(0); + String sheepValue = pedigree.getBsManageTags() != null && !pedigree.getBsManageTags().isEmpty() + ? "羊只:" + pedigree.getBsManageTags() + : "羊只:无"; + sheepCell.setCellValue(sheepValue); + sheepCell.setCellStyle(contentStyle); // 覆盖为内容样式(带边框+字体) + sheet.addMergedRegion(new CellRangeAddress( + pedigreeStartRow, + pedigreeStartRow + 11, + 0, + 0 + )); + + // ========== 2. 父耳号:第2-3列合并前6行 ========== + Row fatherRow = sheet.getRow(pedigreeStartRow); + Cell fatherCell = fatherRow.createCell(1); + String fatherValue = pedigree.getFatherManageTags() != null && !pedigree.getFatherManageTags().isEmpty() + ? "父耳号:" + pedigree.getFatherManageTags() + : "父耳号:无"; + fatherCell.setCellValue(fatherValue); + fatherCell.setCellStyle(contentStyle); + sheet.addMergedRegion(new CellRangeAddress( + pedigreeStartRow, + pedigreeStartRow + 5, + 1, + 2 + )); + + // ========== 3. 母耳号:第2-3列合并后6行 ========== + Row motherRow = sheet.getRow(pedigreeStartRow + 6); + Cell motherCell = motherRow.createCell(1); + String motherValue = pedigree.getMotherManageTags() != null && !pedigree.getMotherManageTags().isEmpty() + ? "母耳号:" + pedigree.getMotherManageTags() + : "母耳号:无"; + motherCell.setCellValue(motherValue); + motherCell.setCellStyle(contentStyle); + sheet.addMergedRegion(new CellRangeAddress( + pedigreeStartRow + 6, + pedigreeStartRow + 11, + 1, + 2 + )); + + // ========== 4. 祖父耳号:第4-6列合并1-3行 ========== + Row grandFatherRow = sheet.getRow(pedigreeStartRow); + Cell grandFatherCell = grandFatherRow.createCell(3); + String grandFatherValue = pedigree.getGrandfatherManageTags() != null && !pedigree.getGrandfatherManageTags().isEmpty() + ? "祖父耳号:" + pedigree.getGrandfatherManageTags() + : "祖父耳号:无"; + grandFatherCell.setCellValue(grandFatherValue); + grandFatherCell.setCellStyle(contentStyle); + sheet.addMergedRegion(new CellRangeAddress( + pedigreeStartRow, + pedigreeStartRow + 2, + 3, + 5 + )); + + // ========== 5. 祖母耳号:第4-6列合并4-6行 ========== + Row grandMotherRow = sheet.getRow(pedigreeStartRow + 3); + Cell grandMotherCell = grandMotherRow.createCell(3); + String grandMotherValue = pedigree.getGrandmotherManageTags() != null && !pedigree.getGrandmotherManageTags().isEmpty() + ? "祖母耳号:" + pedigree.getGrandmotherManageTags() + : "祖母耳号:无"; + grandMotherCell.setCellValue(grandMotherValue); + grandMotherCell.setCellStyle(contentStyle); + sheet.addMergedRegion(new CellRangeAddress( + pedigreeStartRow + 3, + pedigreeStartRow + 5, + 3, + 5 + )); + + // ========== 6. 外祖父耳号:第4-6列合并7-9行 ========== + Row maternalGrandFatherRow = sheet.getRow(pedigreeStartRow + 6); + Cell maternalGrandFatherCell = maternalGrandFatherRow.createCell(3); + String maternalGrandFatherValue = pedigree.getMaternalGrandfatherManageTags() != null && !pedigree.getMaternalGrandfatherManageTags().isEmpty() + ? "外祖父耳号:" + pedigree.getMaternalGrandfatherManageTags() + : "外祖父耳号:无"; + maternalGrandFatherCell.setCellValue(maternalGrandFatherValue); + maternalGrandFatherCell.setCellStyle(contentStyle); + sheet.addMergedRegion(new CellRangeAddress( + pedigreeStartRow + 6, + pedigreeStartRow + 8, + 3, + 5 + )); + + // ========== 7. 外祖母耳号:第4-6列合并10-12行 ========== + Row maternalGrandMotherRow = sheet.getRow(pedigreeStartRow + 9); + Cell maternalGrandMotherCell = maternalGrandMotherRow.createCell(3); + String maternalGrandMotherValue = pedigree.getMaternalGrandmotherManageTags() != null && !pedigree.getMaternalGrandmotherManageTags().isEmpty() + ? "外祖母耳号:" + pedigree.getMaternalGrandmotherManageTags() + : "外祖母耳号:无"; + maternalGrandMotherCell.setCellValue(maternalGrandMotherValue); + maternalGrandMotherCell.setCellStyle(contentStyle); + sheet.addMergedRegion(new CellRangeAddress( + pedigreeStartRow + 9, + pedigreeStartRow + 11, + 3, + 5 + )); + + // 更新rowNum到系谱区块结束行+1 + rowNum = pedigreeStartRow + pedigreeTotalRows; + + } + + // ========== 4. 输出Excel ========== + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String fileName = URLEncoder.encode("羊只系谱_" + System.currentTimeMillis(), "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + + OutputStream os = response.getOutputStream(); + workbook.write(os); + os.flush(); + os.close(); + workbook.close(); + } + + // ========== 新增:填充整行边框的工具方法 ========== + private void fillRowWithBorder(Row row, int startCol, int endCol, CellStyle borderStyle) { + for (int col = startCol; col <= endCol; col++) { + Cell cell = row.getCell(col); + if (cell == null) { + cell = row.createCell(col); + } + // 仅当单元格无样式时设置边框样式(避免覆盖已有内容样式) + if (cell.getCellStyle() == null || cell.getCellStyle().getBorderTop() == BorderStyle.NONE) { + cell.setCellStyle(borderStyle); + } + } + } + + // ========== 样式定义 ========== + private static CellStyle createTitleStyle(Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + Font font = workbook.createFont(); + font.setFontName("微软雅黑"); + font.setFontHeightInPoints((short) 16); + font.setBold(true); + style.setFont(font); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + // 标题样式带完整边框 + style.setBorderTop(BorderStyle.THIN); + style.setBorderBottom(BorderStyle.THIN); + style.setBorderLeft(BorderStyle.THIN); + style.setBorderRight(BorderStyle.THIN); + return style; + } + + private static CellStyle createBlockTitleStyle(Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + Font font = workbook.createFont(); + font.setFontName("微软雅黑"); + font.setFontHeightInPoints((short) 14); + font.setBold(true); + style.setFont(font); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + // 区块标题带完整边框 + style.setBorderTop(BorderStyle.THIN); + style.setBorderBottom(BorderStyle.THIN); + style.setBorderLeft(BorderStyle.THIN); + style.setBorderRight(BorderStyle.THIN); + return style; + } + + private static CellStyle createContentStyle(Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + Font font = workbook.createFont(); + font.setFontName("微软雅黑"); + font.setFontHeightInPoints((short) 12); + style.setFont(font); + style.setAlignment(HorizontalAlignment.LEFT); + style.setVerticalAlignment(VerticalAlignment.CENTER); + // 内容样式带完整边框 + style.setBorderTop(BorderStyle.THIN); + style.setBorderBottom(BorderStyle.THIN); + style.setBorderLeft(BorderStyle.THIN); + style.setBorderRight(BorderStyle.THIN); + return style; + } + + // 新增:纯边框样式(用于空单元格) + private static CellStyle createBorderStyle(Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + // 仅设置边框,无字体/背景色(避免覆盖内容样式) + style.setBorderTop(BorderStyle.THIN); + style.setBorderBottom(BorderStyle.THIN); + style.setBorderLeft(BorderStyle.THIN); + style.setBorderRight(BorderStyle.THIN); + style.setAlignment(HorizontalAlignment.LEFT); + style.setVerticalAlignment(VerticalAlignment.CENTER); + return style; + } + + // 性别数字转文字 + private static String getGenderText(Long gender) { + if (gender == null) return ""; + switch (gender.intValue()) { + case 1: return "母"; + case 2: return "公"; + case 3: return "阉羊"; + case 4: return "兼性"; + default: return ""; + } + } +} \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/base/SheepPedigreeMapper.xml b/zhyc-module/src/main/resources/mapper/base/SheepPedigreeMapper.xml new file mode 100644 index 0000000..d49945d --- /dev/null +++ b/zhyc-module/src/main/resources/mapper/base/SheepPedigreeMapper.xml @@ -0,0 +1,391 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select id, bs_manage_tags, ranch_id, dr_ranch, sheepfold_id, sheepfold_name, electronic_tags, variety_id, variety, family, name, gender, birthday, day_age, month_age, parity, birth_weight, weaning_date, status_id, weaning_weight, weaning_day_age, weaning_daily_gain, current_weight, breed_status_id, breed, bs_father_id, father_manage_tags, bs_mother_id, mother_manage_tags, receptor_id, receptor_manage_tags, father_father_id, grandfather_manage_tags, father_mother_id, grandmother_manage_tags, father_id, maternal_grandfather_manage_tags, mother_id, maternal_grandmother_manage_tags, mating_date, mating_type_id, preg_date, lambing_date, lambing_day, mating_day, gestation_day, expected_date, post_lambing_day, lactation_day, anestrous_day, mating_counts, mating_total, miscarriage_counts, comment, controlled, body, breast, source, source_date, source_ranch_id, source_ranch, update_by, update_time, create_by, create_time, is_delete, sheep_color, group_name from sheep_pedigree + + + + + + + + insert into sheep_pedigree + + id, + bs_manage_tags, + ranch_id, + dr_ranch, + sheepfold_id, + sheepfold_name, + electronic_tags, + variety_id, + variety, + family, + name, + gender, + birthday, + day_age, + month_age, + parity, + birth_weight, + weaning_date, + status_id, + weaning_weight, + weaning_day_age, + weaning_daily_gain, + current_weight, + breed_status_id, + breed, + bs_father_id, + father_manage_tags, + bs_mother_id, + mother_manage_tags, + receptor_id, + receptor_manage_tags, + father_father_id, + grandfather_manage_tags, + father_mother_id, + grandmother_manage_tags, + father_id, + maternal_grandfather_manage_tags, + mother_id, + maternal_grandmother_manage_tags, + mating_date, + mating_type_id, + preg_date, + lambing_date, + lambing_day, + mating_day, + gestation_day, + expected_date, + post_lambing_day, + lactation_day, + anestrous_day, + mating_counts, + mating_total, + miscarriage_counts, + comment, + controlled, + body, + breast, + source, + source_date, + source_ranch_id, + source_ranch, + update_by, + update_time, + create_by, + create_time, + is_delete, + sheep_color, + group_name, + + + #{id}, + #{bsManageTags}, + #{ranchId}, + #{drRanch}, + #{sheepfoldId}, + #{sheepfoldName}, + #{electronicTags}, + #{varietyId}, + #{variety}, + #{family}, + #{name}, + #{gender}, + #{birthday}, + #{dayAge}, + #{monthAge}, + #{parity}, + #{birthWeight}, + #{weaningDate}, + #{statusId}, + #{weaningWeight}, + #{weaningDayAge}, + #{weaningDailyGain}, + #{currentWeight}, + #{breedStatusId}, + #{breed}, + #{bsFatherId}, + #{fatherManageTags}, + #{bsMotherId}, + #{motherManageTags}, + #{receptorId}, + #{receptorManageTags}, + #{fatherFatherId}, + #{grandfatherManageTags}, + #{fatherMotherId}, + #{grandmotherManageTags}, + #{fatherId}, + #{maternalGrandfatherManageTags}, + #{motherId}, + #{maternalGrandmotherManageTags}, + #{matingDate}, + #{matingTypeId}, + #{pregDate}, + #{lambingDate}, + #{lambingDay}, + #{matingDay}, + #{gestationDay}, + #{expectedDate}, + #{postLambingDay}, + #{lactationDay}, + #{anestrousDay}, + #{matingCounts}, + #{matingTotal}, + #{miscarriageCounts}, + #{comment}, + #{controlled}, + #{body}, + #{breast}, + #{source}, + #{sourceDate}, + #{sourceRanchId}, + #{sourceRanch}, + #{updateBy}, + #{updateTime}, + #{createBy}, + #{createTime}, + #{isDelete}, + #{sheepColor}, + #{groupName}, + + + + + update sheep_pedigree + + bs_manage_tags = #{bsManageTags}, + ranch_id = #{ranchId}, + dr_ranch = #{drRanch}, + sheepfold_id = #{sheepfoldId}, + sheepfold_name = #{sheepfoldName}, + electronic_tags = #{electronicTags}, + variety_id = #{varietyId}, + variety = #{variety}, + family = #{family}, + name = #{name}, + gender = #{gender}, + birthday = #{birthday}, + day_age = #{dayAge}, + month_age = #{monthAge}, + parity = #{parity}, + birth_weight = #{birthWeight}, + weaning_date = #{weaningDate}, + status_id = #{statusId}, + weaning_weight = #{weaningWeight}, + weaning_day_age = #{weaningDayAge}, + weaning_daily_gain = #{weaningDailyGain}, + current_weight = #{currentWeight}, + breed_status_id = #{breedStatusId}, + breed = #{breed}, + bs_father_id = #{bsFatherId}, + father_manage_tags = #{fatherManageTags}, + bs_mother_id = #{bsMotherId}, + mother_manage_tags = #{motherManageTags}, + receptor_id = #{receptorId}, + receptor_manage_tags = #{receptorManageTags}, + father_father_id = #{fatherFatherId}, + grandfather_manage_tags = #{grandfatherManageTags}, + father_mother_id = #{fatherMotherId}, + grandmother_manage_tags = #{grandmotherManageTags}, + father_id = #{fatherId}, + maternal_grandfather_manage_tags = #{maternalGrandfatherManageTags}, + mother_id = #{motherId}, + maternal_grandmother_manage_tags = #{maternalGrandmotherManageTags}, + mating_date = #{matingDate}, + mating_type_id = #{matingTypeId}, + preg_date = #{pregDate}, + lambing_date = #{lambingDate}, + lambing_day = #{lambingDay}, + mating_day = #{matingDay}, + gestation_day = #{gestationDay}, + expected_date = #{expectedDate}, + post_lambing_day = #{postLambingDay}, + lactation_day = #{lactationDay}, + anestrous_day = #{anestrousDay}, + mating_counts = #{matingCounts}, + mating_total = #{matingTotal}, + miscarriage_counts = #{miscarriageCounts}, + comment = #{comment}, + controlled = #{controlled}, + body = #{body}, + breast = #{breast}, + source = #{source}, + source_date = #{sourceDate}, + source_ranch_id = #{sourceRanchId}, + source_ranch = #{sourceRanch}, + update_by = #{updateBy}, + update_time = #{updateTime}, + create_by = #{createBy}, + create_time = #{createTime}, + is_delete = #{isDelete}, + sheep_color = #{sheepColor}, + group_name = #{groupName}, + + where id = #{id} + + + + delete from sheep_pedigree where id = #{id} + + + + delete from sheep_pedigree where id in + + #{id} + + + + + + \ No newline at end of file From 7cc0f806bae53eb68173c17d9a389e07a77de688 Mon Sep 17 00:00:00 2001 From: ll <1079863556@qq.com> Date: Thu, 5 Feb 2026 21:56:49 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E9=94=80=E5=94=AE=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=86=E7=A6=BB=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sale/controller/SxCustomerController.java | 5 +- .../controller/SxSheepSaleController.java | 3 + .../zhyc/module/sale/domain/SxCustomer.java | 122 ++++++++++++++---- .../zhyc/module/sale/domain/SxSheepSale.java | 24 ++++ .../service/impl/SxCustomerServiceImpl.java | 10 +- .../service/impl/SxSheepSaleServiceImpl.java | 38 ++++-- .../mapper/sale/SxCustomerMapper.xml | 17 ++- .../mapper/sale/SxSheepSaleMapper.xml | 60 ++++----- 8 files changed, 203 insertions(+), 76 deletions(-) diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxCustomerController.java b/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxCustomerController.java index 5d1bf65..5fc7735 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxCustomerController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxCustomerController.java @@ -66,6 +66,9 @@ public class SxCustomerController extends BaseController { @Log(title = "客户管理", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody SxCustomer sxCustomer) { + // 【新增】自动填充当前登录用户的 userId 和 deptId + sxCustomer.setUserId(getUserId()); + sxCustomer.setDeptId(getDeptId()); return toAjax(sxCustomerService.insertSxCustomer(sxCustomer)); } @@ -82,4 +85,4 @@ public class SxCustomerController extends BaseController { public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(sxCustomerService.deleteSxCustomerByIds(ids)); } -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java b/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java index 307ac92..5cef249 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/controller/SxSheepSaleController.java @@ -78,6 +78,9 @@ public class SxSheepSaleController extends BaseController { @Log(title = "羊只销售记录", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody SxSheepSale sxSheepSale) { + // 【新增】自动填充当前登录用户的 userId 和 deptId + sxSheepSale.setUserId(getUserId()); + sxSheepSale.setDeptId(getDeptId()); return toAjax(sxSheepSaleService.insertSxSheepSale(sxSheepSale)); } diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomer.java b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomer.java index 458b1c4..c6f717b 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomer.java +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxCustomer.java @@ -5,56 +5,134 @@ import org.apache.commons.lang3.builder.ToStringStyle; import com.zhyc.common.annotation.Excel; import com.zhyc.common.core.domain.BaseEntity; +/** + * 客户管理对象 sx_customer + * * @author ruoyi + * @date 2025-08-18 + */ public class SxCustomer extends BaseEntity { private static final long serialVersionUID = 1L; + /** 主键ID */ private Long id; + /** 客户名称 */ @Excel(name = "客户名称") private String name; + /** 客户电话 */ @Excel(name = "客户电话") private String phone; + /** 省 */ @Excel(name = "省") private String province; + /** 市 */ @Excel(name = "市") private String city; + /** 区县 */ @Excel(name = "区县") private String district; + /** 详细地址 */ @Excel(name = "详细地址") private String address; + /** 用户ID */ + private Long userId; + + /** 部门ID */ + private Long deptId; + // Getters and Setters - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - public String getName() { return name; } - public void setName(String name) { this.name = name; } - public String getPhone() { return phone; } - public void setPhone(String phone) { this.phone = phone; } - public String getProvince() { return province; } - public void setProvince(String province) { this.province = province; } - public String getCity() { return city; } - public void setCity(String city) { this.city = city; } - public String getDistrict() { return district; } - public void setDistrict(String district) { this.district = district; } - public String getAddress() { return address; } - public void setAddress(String address) { this.address = address; } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getProvince() { + return province; + } + + public void setProvince(String province) { + this.province = province; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getDistrict() { + return district; + } + + public void setDistrict(String district) { + this.district = district; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) - .append("id", id) - .append("name", name) - .append("phone", phone) - .append("province", province) - .append("city", city) - .append("district", district) - .append("address", address) + .append("id", getId()) + .append("name", getName()) + .append("phone", getPhone()) + .append("province", getProvince()) + .append("city", getCity()) + .append("district", getDistrict()) + .append("address", getAddress()) .append("remark", getRemark()) + .append("userId", getUserId()) + .append("deptId", getDeptId()) .toString(); } -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java index aab27dc..892727e 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/domain/SxSheepSale.java @@ -147,6 +147,12 @@ public class SxSheepSale extends BaseEntity { @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd") private Date createdAt; + /** 用户ID */ + private Long userId; + + /** 部门ID */ + private Long deptId; + // 【新增】非数据库字段:用于前端展示和选择羊舍后传递多个耳号 private List bsManageTagsList; @@ -423,6 +429,22 @@ public class SxSheepSale extends BaseEntity { return createdAt; } + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } + // 【新增】getter 和 setter 方法 public List getBsManageTagsList() { return bsManageTagsList; @@ -531,6 +553,8 @@ public class SxSheepSale extends BaseEntity { .append("handlerId", getHandlerId()) .append("createdBy", getCreatedBy()) .append("createdAt", getCreatedAt()) + .append("userId", getUserId()) + .append("deptId", getDeptId()) .append("remark", getRemark()) .append("customerName", getCustomerName()) .append("customerPhone", getCustomerPhone()) diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxCustomerServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxCustomerServiceImpl.java index 2973e30..1e43d69 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxCustomerServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxCustomerServiceImpl.java @@ -3,6 +3,7 @@ package com.zhyc.module.sale.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.zhyc.common.annotation.DataScope; // 【新增】引入数据权限注解 import com.zhyc.module.sale.mapper.SxCustomerMapper; import com.zhyc.module.sale.domain.SxCustomer; import com.zhyc.module.sale.service.ISxCustomerService; @@ -17,7 +18,14 @@ public class SxCustomerServiceImpl implements ISxCustomerService { return sxCustomerMapper.selectSxCustomerById(id); } + /** + * 查询客户管理列表 + * 【新增】添加数据权限过滤注解 + * deptAlias = "c": 对应 Mapper.xml 中表 sx_customer 的别名 c + * userAlias = "c": 对应 Mapper.xml 中表 sx_customer 的别名 c + */ @Override + @DataScope(deptAlias = "c", userAlias = "c") public List selectSxCustomerList(SxCustomer sxCustomer) { return sxCustomerMapper.selectSxCustomerList(sxCustomer); } @@ -41,4 +49,4 @@ public class SxCustomerServiceImpl implements ISxCustomerService { public int deleteSxCustomerById(Long id) { return sxCustomerMapper.deleteSxCustomerById(id); } -} +} \ No newline at end of file diff --git a/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java index 8375af5..dc9c026 100644 --- a/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java +++ b/zhyc-module/src/main/java/com/zhyc/module/sale/service/impl/SxSheepSaleServiceImpl.java @@ -5,8 +5,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import com.zhyc.common.exception.ServiceException; +import com.zhyc.common.annotation.DataScope; // 【新增】引入数据权限注解 import com.zhyc.module.sale.mapper.SxSheepSaleMapper; import com.zhyc.module.sale.domain.SxSheepSale; import com.zhyc.module.sale.service.ISxSheepSaleService; @@ -35,11 +34,15 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { /** * 查询羊只销售记录列表 + * 【新增】添加数据权限过滤注解 + * deptAlias = "s": 对应 Mapper.xml 中表 sx_sheep_sale 的别名 s + * userAlias = "s": 对应 Mapper.xml 中表 sx_sheep_sale 的别名 s * * @param sxSheepSale 羊只销售记录 * @return 羊只销售记录 */ @Override + @DataScope(deptAlias = "s", userAlias = "s") public List selectSxSheepSaleList(SxSheepSale sxSheepSale) { return sxSheepSaleMapper.selectSxSheepSaleList(sxSheepSale); } @@ -51,9 +54,8 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { * @return 结果 */ @Override - @Transactional(rollbackFor = Exception.class) // 事务控制 public int insertSxSheepSale(SxSheepSale sxSheepSale) { - // 1. 业务验证 + // 1. 业务验证 (例如:销售日期不能为空,淘汰销售必须填写疾病类型等) validateSalesFields(sxSheepSale); // 2. 自动计算逻辑 @@ -80,7 +82,6 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { * @return 结果 */ @Override - @Transactional(rollbackFor = Exception.class) public int updateSxSheepSale(SxSheepSale sxSheepSale) { // 1. 业务验证 validateSalesFields(sxSheepSale); @@ -88,7 +89,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { // 2. 自动计算逻辑 calculateSalesFields(sxSheepSale); - // 3. 处理耳号列表 + // 3. 处理耳号列表(多个耳号用逗号分隔) if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { sxSheepSale.setBsManageTags(String.join(",", sxSheepSale.getBsManageTagsList())); } @@ -120,7 +121,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { } /** - * 根据耳号查询羊只信息 + * 【新增】根据耳号查询羊只信息 */ @Override public SxSheepSale selectSheepInfoByTag(String bsManageTags) { @@ -128,7 +129,7 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { } /** - * 自动计算总价、平均体重、平均单只价格 + * 【新增】自动计算总价、平均体重、平均单只价格 */ private void calculateSalesFields(SxSheepSale sxSheepSale) { String pricingMethod = sxSheepSale.getPricingMethod(); @@ -139,48 +140,59 @@ public class SxSheepSaleServiceImpl implements ISxSheepSaleService { if (sxSheepSale.getBsManageTagsList() != null && !sxSheepSale.getBsManageTagsList().isEmpty()) { sheepCount = sxSheepSale.getBsManageTagsList().size(); } else if (sxSheepSale.getBsManageTags() != null && !sxSheepSale.getBsManageTags().isEmpty()) { + // 如果前端没有传递列表,但有逗号分隔的字符串,也计算数量 sheepCount = sxSheepSale.getBsManageTags().split(",").length; } if ("按个体".equals(pricingMethod)) { + // 总价 = 单价 * 数量 if (unitPrice != null) { sxSheepSale.setTotalPrice(unitPrice.multiply(new BigDecimal(sheepCount))); } + // 平均单只价格就是单价 sxSheepSale.setAvgPricePerSheep(unitPrice); + } else if ("按体重".equals(pricingMethod)) { BigDecimal totalWeight = sxSheepSale.getTotalWeight(); + // 总价 = 单价 * 总重量 if (unitPrice != null && totalWeight != null) { sxSheepSale.setTotalPrice(unitPrice.multiply(totalWeight)); } + // 平均体重 = 总重量 / 数量 if (totalWeight != null && sheepCount > 0) { sxSheepSale.setAvgWeight(totalWeight.divide(new BigDecimal(sheepCount), 2, RoundingMode.HALF_UP)); } + // 平均单只价格 = 总价 / 数量 if (sxSheepSale.getTotalPrice() != null && sheepCount > 0) { sxSheepSale.setAvgPricePerSheep(sxSheepSale.getTotalPrice().divide(new BigDecimal(sheepCount), 2, RoundingMode.HALF_UP)); } } + // 可以添加其他计价方式的逻辑 } /** - * 业务字段验证 (使用 ServiceException) + * 【新增】业务字段验证 */ private void validateSalesFields(SxSheepSale sxSheepSale) { + // 验证销售日期不能为空 if (sxSheepSale.getSaleDate() == null) { - throw new ServiceException("销售日期不能为空!"); + throw new RuntimeException("销售日期不能为空!"); } String saleType = sxSheepSale.getSaleType(); + // 如果销售类别是"淘汰销售"或"淘汰屠宰",则疾病类型和班组不能为空 if ("淘汰销售".equals(saleType) || "淘汰屠宰".equals(saleType)) { if (sxSheepSale.getDiseaseType() == null) { - throw new ServiceException("淘汰销售或淘汰屠宰必须选择疾病类型!"); + throw new RuntimeException("淘汰销售或淘汰屠宰必须选择疾病类型!"); } if (sxSheepSale.getGroupCode() == null) { - throw new ServiceException("淘汰销售或淘汰屠宰必须选择班组!"); + throw new RuntimeException("淘汰销售或淘汰屠宰必须选择班组!"); } } + // 如果疾病类型是"病残羊",则次要原因不能为空 if ("病残羊".equals(sxSheepSale.getDiseaseType())) { if (sxSheepSale.getSecondaryReason() == null || sxSheepSale.getSecondaryReason().trim().isEmpty()) { - throw new ServiceException("疾病类型为病残羊时,必须填写次要原因!"); + throw new RuntimeException("疾病类型为病残羊时,必须填写次要原因!"); } } } diff --git a/zhyc-module/src/main/resources/mapper/sale/SxCustomerMapper.xml b/zhyc-module/src/main/resources/mapper/sale/SxCustomerMapper.xml index 97c0954..b6f20ac 100644 --- a/zhyc-module/src/main/resources/mapper/sale/SxCustomerMapper.xml +++ b/zhyc-module/src/main/resources/mapper/sale/SxCustomerMapper.xml @@ -11,23 +11,26 @@ + + - SELECT id, name, phone, province, city, district, address, remark - FROM sx_customer + SELECT c.id, c.name, c.phone, c.province, c.city, c.district, c.address, c.remark, c.user_id, c.dept_id + FROM sx_customer c @@ -40,6 +43,8 @@ district, address, remark, + user_id, + dept_id, #{name}, @@ -49,6 +54,8 @@ #{district}, #{address}, #{remark}, + #{userId}, + #{deptId}, @@ -76,4 +83,4 @@ #{id} - + \ No newline at end of file diff --git a/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml b/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml index b8e1e2f..b312e02 100644 --- a/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml +++ b/zhyc-module/src/main/resources/mapper/sale/SxSheepSaleMapper.xml @@ -36,33 +36,28 @@ - - - - - + + - SELECT - s.id, s.bs_manage_tags, s.sheepfold_id, s.variety, s.sheep_name, s.gender, s.month_age, s.parity, s.breed, - s.post_lambing_day, s.lactation_day, s.lambing_day, s.event_type, s.sale_date, s.pricing_method, - s.unit_price, s.total_price, s.total_weight, s.avg_weight, s.avg_price_per_sheep, s.sale_type, - s.disease_type, s.secondary_reason, s.group_code, s.customer_id, s.sales_person_id, - s.quarantine_no, s.approval_no, s.technician_id, s.handler_id, s.created_by, s.created_at, s.remark, - c.name AS customer_name, - c.phone AS customer_phone, - CONCAT(IFNULL(c.province,''), IFNULL(c.city,''), IFNULL(c.district,''), IFNULL(c.address,'')) AS customer_address, - u.nick_name AS sales_person_name - FROM sx_sheep_sale s - LEFT JOIN sx_customer c ON s.customer_id = c.id - LEFT JOIN sys_user u ON s.sales_person_id = u.user_id + select s.id, s.bs_manage_tags, s.sheepfold_id, s.variety, s.sheep_name, s.gender, s.month_age, s.parity, s.breed, s.post_lambing_day, s.lactation_day, s.lambing_day, s.event_type, s.sale_date, s.pricing_method, s.unit_price, s.total_price, s.total_weight, s.avg_weight, s.avg_price_per_sheep, s.sale_type, s.disease_type, s.secondary_reason, s.group_code, s.customer_id, s.sales_person_id, s.quarantine_no, s.approval_no, s.technician_id, s.handler_id, s.created_by, s.created_at, s.remark, s.user_id, s.dept_id + from sx_sheep_sale s select - bs_manage_tags, variety, name as sheep_name, gender, month_age, parity, breed, - post_lambing_day, lactation_day, lambing_day, sheepfold_id + bs_manage_tags, + variety, + name as sheep_name, + gender, + month_age, + parity, + breed, + post_lambing_day, + lactation_day, + lambing_day, + sheepfold_id from sheep_file @@ -74,20 +69,13 @@ @@ -131,6 +119,8 @@ created_by, created_at, remark, + user_id, + dept_id, #{bsManageTags}, @@ -165,6 +155,8 @@ #{createdBy}, #{createdAt}, #{remark}, + #{userId}, + #{deptId},