编辑matype不能保存的问题

This commit is contained in:
sxu 2024-10-25 17:29:34 +08:00
parent c2bfd254bb
commit ed588f5797
1 changed files with 7 additions and 1 deletions

View File

@ -20,6 +20,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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_NUM;
import static com.bonus.sgzb.common.core.web.page.TableSupport.PAGE_SIZE; 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) { public AjaxResult edit(@RequestBody MaType maType) {
Long parentId = maType.getParentId(); Long parentId = maType.getParentId();
List<MaType> subMas = maTypeMapper.getListByParentId(parentId, null); List<MaType> subMas = maTypeMapper.getListByParentId(parentId, null);
boolean containsSameBrother = subMas.stream().anyMatch(o -> o.getTypeName().equals(maType.getTypeName())); List<MaType> 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) { if (containsSameBrother) {
return AjaxResult.error("修改失败,同级存在相同名称"); return AjaxResult.error("修改失败,同级存在相同名称");
} }