Compare commits

...

2 Commits

3 changed files with 24 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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>