修改分组页面,新增名称重复校验以及查询的bug
This commit is contained in:
parent
02634eb7b6
commit
e78e0c039b
@ -2,6 +2,7 @@ package com.zhyc.module.base.mapper;
|
||||
|
||||
import com.zhyc.module.base.domain.BasSheepGroup;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -64,4 +65,8 @@ public interface BasSheepGroupMapper
|
||||
|
||||
List<BasSheepGroup> selectLeafNodes();
|
||||
|
||||
|
||||
// 新增方法:根据父节点和分组名称查询是否存在
|
||||
BasSheepGroup selectByParentIdAndGroupName(@Param("parentId") Long parentId, @Param("groupName") String groupName);
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.zhyc.module.base.service.impl;
|
||||
|
||||
import com.zhyc.common.exception.ServiceException;
|
||||
import com.zhyc.common.utils.DateUtils;
|
||||
import com.zhyc.module.base.domain.BasSheepGroup;
|
||||
import com.zhyc.module.base.mapper.BasSheepGroupMapper;
|
||||
@ -68,6 +69,12 @@ public class BasSheepGroupServiceImpl implements IBasSheepGroupService
|
||||
@Override
|
||||
public int insertBasSheepGroup(BasSheepGroup basSheepGroup)
|
||||
{
|
||||
// ✅ 新增唯一性校验
|
||||
BasSheepGroup existing = basSheepGroupMapper.selectByParentIdAndGroupName(
|
||||
basSheepGroup.getParentId(), basSheepGroup.getGroupName());
|
||||
if (existing != null) {
|
||||
throw new ServiceException("同一分支下已存在该分组名称");
|
||||
}
|
||||
basSheepGroup.setCreateTime(DateUtils.getNowDate());
|
||||
return basSheepGroupMapper.insertBasSheepGroup(basSheepGroup);
|
||||
}
|
||||
@ -81,6 +88,12 @@ public class BasSheepGroupServiceImpl implements IBasSheepGroupService
|
||||
@Override
|
||||
public int updateBasSheepGroup(BasSheepGroup basSheepGroup)
|
||||
{
|
||||
// ✅ 新增唯一性校验(排除当前记录)
|
||||
BasSheepGroup existing = basSheepGroupMapper.selectByParentIdAndGroupName(
|
||||
basSheepGroup.getParentId(), basSheepGroup.getGroupName());
|
||||
if (existing != null && !existing.getGroupId().equals(basSheepGroup.getGroupId())) {
|
||||
throw new ServiceException("同一分支下已存在该分组名称");
|
||||
}
|
||||
basSheepGroup.setUpdateTime(DateUtils.getNowDate());
|
||||
return basSheepGroupMapper.updateBasSheepGroup(basSheepGroup);
|
||||
}
|
||||
|
||||
@ -126,5 +126,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="selectByParentIdAndGroupName" resultMap="BasSheepGroupResult">
|
||||
SELECT * FROM bas_sheep_group
|
||||
WHERE parent_id = #{parentId} AND group_name = #{groupName}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
Loading…
x
Reference in New Issue
Block a user