diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/base/controller/MaTypeController.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/base/controller/MaTypeController.java index b1516c2..cb0a8b0 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/base/controller/MaTypeController.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/base/controller/MaTypeController.java @@ -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("未新增成功,请查看同一层级是否有重名的类型!"); + } } /** diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/base/service/impl/MaTypeServiceImpl.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/base/service/impl/MaTypeServiceImpl.java index 59d9ab7..90c43a9 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/base/service/impl/MaTypeServiceImpl.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/base/service/impl/MaTypeServiceImpl.java @@ -55,6 +55,11 @@ public class MaTypeServiceImpl implements ITypeService { @Transactional public int insertMaType(MaType maType) { Long parentId = maType.getParentId(); + List 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));