| | |
| | | if( category.getId() == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | if(Constants.equalsInteger(category.getId(),category.getParentId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,父级不能设置为自身!"); |
| | | } |
| | | category.setType(null);//类型不支持修改 |
| | | Category model = categoryMapper.selectById(category.getId()); |
| | | if(model ==null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)) { |
| | |
| | | .eq(Category::getIsdeleted,Constants.ZERO)) >0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,名称不能重复~"); |
| | | }*/ |
| | | String oldIdPath = model.getIdPath(); |
| | | String oldNamePath = model.getNamePath(); |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | category.setIdPath(category.getId()+"/");//名称路径 |
| | | category.setNamePath(category.getName());//名称路径 |
| | |
| | | } |
| | | category.setEditDate(new Date()); |
| | | category.setEditor(user.getId()); |
| | | categoryMapper.updateById(category); |
| | | categoryMapper.update(null,new UpdateWrapper<Category>().lambda() |
| | | .eq(Category::getId,category.getId()) |
| | | .set(Category::getEditDate,category.getEditDate()) |
| | | .set(Category::getEditor,category.getEditor()) |
| | | .set(Category::getName,category.getName()) |
| | | .set(Category::getParentId,category.getParentId()) |
| | | .set(Category::getSortnum,category.getSortnum()) |
| | | .set(Category::getRemark,category.getRemark()) |
| | | .set(Category::getNamePath,category.getNamePath()) |
| | | .set(Category::getIdPath,category.getId()) |
| | | ); |
| | | //修改全部下级的编码和名称路径 |
| | | categoryMapper.update(null,new UpdateWrapper<Category>().lambda() |
| | | .likeRight(Category::getIdPath,oldIdPath) |
| | | .set(Category::getEditDate,category.getEditDate()) |
| | | .set(Category::getEditor,category.getEditor()) |
| | | .setSql("id_path=replace(id_path,'"+oldIdPath+"','"+category.getIdParentPath()+"')") |
| | | .setSql("name_path=replace(name_path,'"+oldNamePath+"/','"+category.getName()+"/')") |
| | | ); |
| | | } |
| | | |
| | | @Override |