新增type时判断是否重名

This commit is contained in:
sxu 2024-08-21 18:33:08 +08:00
parent 97136aecc9
commit 6b707ff353
2 changed files with 11 additions and 1 deletions

View File

@ -234,7 +234,12 @@ public class MaTypeController extends BaseController {
@PostMapping
public AjaxResult add(@RequestBody MaType maType)
{
return toAjax(iTypeService.insertMaType(maType));
int result = iTypeService.insertMaType(maType);
if (result > 0) {
return success(toAjax(iTypeService.insertMaType(maType)));
} else {
return AjaxResult.error("未新增成功,请查看同一层级是否有重名的类型!");
}
}
/**

View File

@ -55,6 +55,11 @@ public class MaTypeServiceImpl implements ITypeService {
@Transactional
public int insertMaType(MaType maType) {
Long parentId = maType.getParentId();
List<MaType> subMas = maTypeMapper.getListByParentId(parentId, null);
boolean containsSameBrother = subMas.stream().anyMatch(o -> o.getTypeName().contains(maType.getTypeName()));
if (containsSameBrother) {
return 0;
}
MaType maType1 = maTypeMapper.selectMaTypeByTypeId(parentId);
String level = maType1.getLevel();
maType.setLevel(String.valueOf(Integer.parseInt(level) + 1));