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 66fa3c0..d583f6e 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 @@ -20,6 +20,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; import static com.bonus.sgzb.common.core.web.page.TableSupport.PAGE_NUM; import static com.bonus.sgzb.common.core.web.page.TableSupport.PAGE_SIZE; @@ -270,7 +272,11 @@ public class MaTypeController extends BaseController { public AjaxResult edit(@RequestBody MaType maType) { Long parentId = maType.getParentId(); List subMas = maTypeMapper.getListByParentId(parentId, null); - boolean containsSameBrother = subMas.stream().anyMatch(o -> o.getTypeName().equals(maType.getTypeName())); + List filteredItems = subMas.stream().collect(Collectors.toList()); + if (Objects.nonNull(maType.getTypeId())) { + filteredItems = subMas.stream().filter(item -> !maType.getTypeId().equals(item.getTypeId())).collect(Collectors.toList()); + } + boolean containsSameBrother = filteredItems.stream().anyMatch(o -> o.getTypeName().equals(maType.getTypeName())); if (containsSameBrother) { return AjaxResult.error("修改失败,同级存在相同名称"); }