| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageDTO; |
| | | import com.ruoyi.common.enums.ShowStatusEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.BeanUtils; |
| | | import com.ruoyi.common.utils.CollUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | |
| | | import com.ruoyi.system.mapper.TbFieldCategoryMapper; |
| | | import com.ruoyi.system.query.FieldCategoryQuery; |
| | | import com.ruoyi.system.service.TbFieldCategoryService; |
| | | import com.ruoyi.system.vo.FieldCategoryDetailVO; |
| | | import com.ruoyi.system.vo.FieldCategoryVO; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | } |
| | | |
| | | private void updateCategoryAndChildren(Integer id, ShowStatusEnum status) { |
| | | TbFieldCategory category = this.getById(id); |
| | | if (Objects.isNull(category)) { |
| | | throw new RuntimeException("非法id"); |
| | | } |
| | | TbFieldCategory category = this.validateParam(id); |
| | | this.lambdaUpdate() |
| | | .eq(TbFieldCategory::getId, id) |
| | | .set(TbFieldCategory::getStatus, status) |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void delete(Integer id) { |
| | | //一级分类 |
| | | TbFieldCategory category = this.getById(id); |
| | | if (Objects.isNull(category)) { |
| | | throw new RuntimeException("非法参数"); |
| | | } |
| | | validateParam(id); |
| | | //查询是否有二级分类 |
| | | List<TbFieldCategory> threeCategoryList = this.lambdaQuery().eq(TbFieldCategory::getParentId, id).list(); |
| | | if (CollectionUtils.isNotEmpty(threeCategoryList)) { |
| | |
| | | this.removeById(id); |
| | | } |
| | | |
| | | private TbFieldCategory validateParam(Integer id) { |
| | | TbFieldCategory category = this.getById(id); |
| | | if (Objects.isNull(category)) { |
| | | throw new ServiceException("非法参数"); |
| | | } |
| | | return category; |
| | | } |
| | | |
| | | @Override |
| | | public void edit(FieldCategoryUpdateDTO dto) { |
| | | validateParam(dto.getId()); |
| | | //更新一级分类 |
| | | updateCategory(dto); |
| | | List<FieldCategoryUpdateDTO> children = dto.getChildren(); |
| | |
| | | .list(); |
| | | return BeanUtils.copyList(list, FieldCategoryVO.class); |
| | | } |
| | | |
| | | @Override |
| | | public FieldCategoryDetailVO getDetailsById(Integer id) { |
| | | TbFieldCategory oneCategory = this.getById(id); |
| | | if (Objects.isNull(oneCategory)) { |
| | | return new FieldCategoryDetailVO(); |
| | | } |
| | | FieldCategoryDetailVO vo = BeanUtils.copyBean(oneCategory, FieldCategoryDetailVO.class); |
| | | //根据一级分类id,查询二级分类 |
| | | List<TbFieldCategory> twoCategoryList = this.lambdaQuery().eq(TbFieldCategory::getParentId, oneCategory.getId()).list(); |
| | | twoCategoryList.forEach(item->{ |
| | | FieldCategoryDetailVO twoCategoryVO = BeanUtils.copyBean(item, FieldCategoryDetailVO.class); |
| | | vo.getChildren().add(twoCategoryVO); |
| | | //根据二级分类id,查询三级分类 |
| | | List<TbFieldCategory> threeCategoryList = this.lambdaQuery().eq(TbFieldCategory::getParentId, item.getId()).list(); |
| | | threeCategoryList.forEach(threeCategory->{ |
| | | FieldCategoryDetailVO threeCategoryVO = BeanUtils.copyBean(threeCategory, FieldCategoryDetailVO.class); |
| | | twoCategoryVO.getChildren().add(threeCategoryVO); |
| | | }); |
| | | }); |
| | | return vo; |
| | | } |
| | | } |