新增type时判断是否重名
This commit is contained in:
parent
97136aecc9
commit
6b707ff353
|
|
@ -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("未新增成功,请查看同一层级是否有重名的类型!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue