From 6b707ff3530abe31244d7eeafb1b197bcbac6e87 Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Wed, 21 Aug 2024 18:33:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Etype=E6=97=B6=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=98=AF=E5=90=A6=E9=87=8D=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bonus/sgzb/base/controller/MaTypeController.java | 7 ++++++- .../bonus/sgzb/base/service/impl/MaTypeServiceImpl.java | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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));