From 4f48b75b433e46735656f5afc788fdd97495db1e Mon Sep 17 00:00:00 2001
From: zyh <2066096076@qq.com>
Date: Mon, 4 Aug 2025 09:17:14 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=A4=E6=96=AD=E7=BE=8A=E5=8F=AA=E7=9A=84?=
=?UTF-8?q?=E5=88=A0=E9=99=A4/=E6=9C=AA=E5=88=A0=E9=99=A4=E7=8A=B6?=
=?UTF-8?q?=E6=80=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../module/base/mapper/BasSheepMapper.java | 2 ++
.../service/impl/ScAddSheepServiceImpl.java | 17 ++++++++-----
.../resources/mapper/base/BasSheepMapper.xml | 25 +++++++++++++------
3 files changed, 31 insertions(+), 13 deletions(-)
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 1b16800..4baaf89 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
@@ -78,4 +78,6 @@ public interface BasSheepMapper
//用于校验改耳号部分新管理/电子耳号
int existsByManageTag(@Param("tag") String tag);
int existsByElectronicTag(@Param("tag") String tag);
+
+
}
diff --git a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/service/impl/ScAddSheepServiceImpl.java b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/service/impl/ScAddSheepServiceImpl.java
index 278490e..b6ed6b4 100644
--- a/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/service/impl/ScAddSheepServiceImpl.java
+++ b/zhyc-module/src/main/java/com/zhyc/module/produce/manage_sheep/service/impl/ScAddSheepServiceImpl.java
@@ -36,9 +36,9 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
@Override
@Transactional(rollbackFor = Exception.class)
public boolean insertScAddSheep(ScAddSheep scAddSheep) {
- ScAddSheep exist = scAddSheepMapper.selectByEarNumber(scAddSheep.getEarNumber());
- if (exist != null) {
- throw new ServiceException("添加失败,耳号重复");
+ BasSheep existSheep =basSheepService.selectBasSheepByManageTags(scAddSheep.getEarNumber().trim());
+ if (existSheep != null) {
+ throw new ServiceException("添加失败,耳号已存在");
}
boolean ok = scAddSheepMapper.insert(scAddSheep) > 0;
@@ -101,6 +101,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
for (int i = 0; i < list.size(); i++) {
ScAddSheep sheep = list.get(i);
try {
+ // 处理品种名称转换为品种ID
if (StringUtils.isNotBlank(sheep.getVarietyName())) {
Long varietyId = basSheepVarietyMapper.selectIdByName(sheep.getVarietyName());
if (varietyId == null) {
@@ -121,6 +122,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
continue;
}
+ // 处理羊舍名称转换为羊舍ID
if (StringUtils.isNotBlank(sheep.getSheepfoldNameExcel())) {
DaSheepfold param = new DaSheepfold();
param.setSheepfoldName(sheep.getSheepfoldNameExcel());
@@ -137,6 +139,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
sheep.setSheepfold(foldList.get(0).getId().intValue());
}
+ // 校验耳号是否为空
if (StringUtils.isBlank(sheep.getEarNumber())) {
failure++;
failureMsg.append("
第")
@@ -145,17 +148,19 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
continue;
}
- ScAddSheep exist = scAddSheepMapper.selectByEarNumber(sheep.getEarNumber());
- if (exist != null) {
+ // 核心校验:判断羊只基本信息表中是否存在未删除的同名耳号
+ BasSheep existSheep = basSheepService.selectBasSheepByManageTags(sheep.getEarNumber().trim());
+ if (existSheep != null) {
failure++;
failureMsg.append("
第")
.append(i + 1)
- .append("行:耳号已存在【")
+ .append("行:耳号已存在且未删除【")
.append(sheep.getEarNumber())
.append("】");
continue;
}
+ // 执行导入(新增或更新)
if (updateSupport && sheep.getId() != null) {
sheep.setUpdateBy(operName);
updateScAddSheep(sheep);
diff --git a/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml b/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml
index c39e3a5..f42546a 100644
--- a/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml
+++ b/zhyc-module/src/main/resources/mapper/base/BasSheepMapper.xml
@@ -128,7 +128,8 @@
and source_date = #{sourceDate}
and source_ranch_id = #{sourceRanchId}
and comment = #{comment}
- and is_delete = #{isDelete}
+ and is_delete = 0
+ and is_delete = #{isDelete}
@@ -151,20 +152,24 @@
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} LIMIT 1
+ WHERE s.manage_tags = #{manageTags}
+ AND s.is_delete = 0 LIMIT 1