| | |
| | | updateCategoryAndChildren(dto.getId(), dto.getStatus()); |
| | | } |
| | | |
| | | private void updateCategoryAndChildren(Integer id, ShowStatusEnum status) { |
| | | private void updateCategoryAndChildren(Long id, ShowStatusEnum status) { |
| | | TbFieldCategory category = this.validateParam(id); |
| | | this.lambdaUpdate() |
| | | .eq(TbFieldCategory::getId, id) |
| | |
| | | .update(); |
| | | List<TbFieldCategory> children = this.lambdaQuery().eq(TbFieldCategory::getParentId, category.getId()).list(); |
| | | if (CollUtils.isNotEmpty(children)) { |
| | | List<Integer> childIds = children.stream().map(TbFieldCategory::getId).collect(Collectors.toList()); |
| | | List<Long> childIds = children.stream().map(TbFieldCategory::getId).collect(Collectors.toList()); |
| | | childIds.forEach(childId -> updateCategoryAndChildren(childId, status)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteChildren(Integer id) { |
| | | public void deleteChildren(Long id) { |
| | | //认定为二级分类 |
| | | TbFieldCategory category = this.getById(id); |
| | | if (Objects.nonNull(category)) { |
| | | //查询是否有三级分类 |
| | | List<TbFieldCategory> threeCategoryList = this.lambdaQuery().eq(TbFieldCategory::getParentId, id).list(); |
| | | if (CollectionUtils.isNotEmpty(threeCategoryList)) { |
| | | List<Integer> ids = threeCategoryList.stream().map(TbFieldCategory::getId).collect(Collectors.toList()); |
| | | List<Long> ids = threeCategoryList.stream().map(TbFieldCategory::getId).collect(Collectors.toList()); |
| | | //删除该二级分类下面的三级分类 |
| | | this.removeByIds(ids); |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void delete(Integer id) { |
| | | public void delete(Long id) { |
| | | //一级分类 |
| | | validateParam(id); |
| | | //查询是否有二级分类 |
| | | List<TbFieldCategory> threeCategoryList = this.lambdaQuery().eq(TbFieldCategory::getParentId, id).list(); |
| | | if (CollectionUtils.isNotEmpty(threeCategoryList)) { |
| | | List<Integer> ids = threeCategoryList.stream().map(TbFieldCategory::getId).collect(Collectors.toList()); |
| | | List<Long> ids = threeCategoryList.stream().map(TbFieldCategory::getId).collect(Collectors.toList()); |
| | | //查询三级分类 |
| | | List<TbFieldCategory> list = this.lambdaQuery().in(TbFieldCategory::getParentId, ids).list(); |
| | | if (CollectionUtils.isNotEmpty(list)) { |
| | | List<Integer> ids1 = list.stream().map(TbFieldCategory::getId).collect(Collectors.toList()); |
| | | List<Long> ids1 = list.stream().map(TbFieldCategory::getId).collect(Collectors.toList()); |
| | | //删除三级分类 |
| | | this.removeByIds(ids1); |
| | | } |
| | |
| | | this.removeById(id); |
| | | } |
| | | |
| | | private TbFieldCategory validateParam(Integer id) { |
| | | private TbFieldCategory validateParam(Long id) { |
| | | TbFieldCategory category = this.getById(id); |
| | | if (Objects.isNull(category)) { |
| | | throw new ServiceException("非法参数"); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<FieldCategoryVO> queryFieldCategories(Integer id) { |
| | | public List<FieldCategoryVO> queryFieldCategories(Long id) { |
| | | List<TbFieldCategory> list = this.lambdaQuery() |
| | | .select(TbFieldCategory::getId,TbFieldCategory::getFieldCategoryName) |
| | | .eq(TbFieldCategory::getParentId, id) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public FieldCategoryDetailVO getDetailsById(Integer id) { |
| | | public FieldCategoryDetailVO getDetailsById(Long id) { |
| | | TbFieldCategory oneCategory = this.getById(id); |
| | | if (Objects.isNull(oneCategory)) { |
| | | return new FieldCategoryDetailVO(); |