| | |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageVO; |
| | | import com.ruoyi.common.basic.PageDTO; |
| | | import com.ruoyi.common.enums.ShowStatus; |
| | | import com.ruoyi.common.utils.BeanUtils; |
| | | import com.ruoyi.common.utils.CollUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.domain.TbFieldCategory; |
| | | import com.ruoyi.system.dto.FieldCategoryDTO; |
| | | import com.ruoyi.system.dto.ShowHideDTO; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PageVO<FieldCategoryVO> queryPage(FieldCategoryQuery query) { |
| | | public PageDTO<FieldCategoryVO> queryPage(FieldCategoryQuery query) { |
| | | Page<TbFieldCategory> page = this.lambdaQuery() |
| | | .like(StringUtils.isNotBlank(query.getFieldCategoryName()), TbFieldCategory::getFieldCategoryName, query.getFieldCategoryName()) |
| | | .eq(ObjectUtils.isNotEmpty(query.getStatus()), TbFieldCategory::getStatus, query.getStatus()) |
| | | .eq(TbFieldCategory::getParentId, 0) |
| | | .orderByDesc(TbFieldCategory::getCreateTime) |
| | | .page(new Page<>(query.getPageNum(), query.getPageSize())); |
| | | PageVO<FieldCategoryVO> pageVO = new PageVO<>(); |
| | | pageVO.setPageNo(page.getPages()); |
| | | pageVO.setPageSize(page.getSize()); |
| | | pageVO.setTotalPages(page.getTotal()); |
| | | pageVO.setTotalCount(page.getTotal()); |
| | | pageVO.setRecords(page.getRecords().stream().map(item -> { |
| | | FieldCategoryVO fieldCategoryVO = new FieldCategoryVO(); |
| | | BeanUtils.copyBeanProp(fieldCategoryVO, item); |
| | | return fieldCategoryVO; |
| | | }).collect(Collectors.toList())); |
| | | return pageVO; |
| | | if (CollUtils.isEmpty(page.getRecords())) { |
| | | return PageDTO.empty(page); |
| | | } |
| | | return PageDTO.of(page, FieldCategoryVO.class); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void showHide(ShowHideDTO dto) { |
| | | TbFieldCategory category = this.getById(dto.getId()); |
| | | updateCategoryAndChildren(dto.getId(), dto.getStatus()); |
| | | } |
| | | |
| | | private void updateCategoryAndChildren(Integer id, Integer status) { |
| | | TbFieldCategory category = this.getById(id); |
| | | if (Objects.isNull(category)) { |
| | | throw new RuntimeException("非法id"); |
| | | } |
| | | this.lambdaUpdate().eq(TbFieldCategory::getId, dto.getId()).set(TbFieldCategory::getStatus, dto.getStatus()); |
| | | this.lambdaUpdate() |
| | | .eq(TbFieldCategory::getId, id) |
| | | .set(TbFieldCategory::getStatus, status) |
| | | .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()); |
| | | childIds.forEach(childId -> updateCategoryAndChildren(childId, status)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | public void delete(Integer id) { |
| | | //一级分类 |
| | | TbFieldCategory category = this.getById(id); |
| | | if (Objects.isNull(category)) { |
| | | throw new RuntimeException("非法参数"); |
| | | } |
| | | //查询是否有二级分类 |
| | | List<TbFieldCategory> threeCategoryList = this.lambdaQuery().eq(TbFieldCategory::getParentId, id).list(); |
| | | if (CollectionUtils.isNotEmpty(threeCategoryList)) { |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | private void updateCategory(FieldCategoryUpdateDTO dto) { |
| | | if (dto == null) return; |
| | | this.lambdaUpdate() |
| | |
| | | .eq(TbFieldCategory::getId, dto.getId()) |
| | | .update(); |
| | | } |
| | | |
| | | @Override |
| | | public List<FieldCategoryVO> queryFieldCategories(Integer id) { |
| | | List<TbFieldCategory> list = this.lambdaQuery() |
| | | .select(TbFieldCategory::getId,TbFieldCategory::getFieldCategoryName) |
| | | .eq(TbFieldCategory::getParentId, id) |
| | | .eq(TbFieldCategory::getStatus, ShowStatus.SHOW) |
| | | .list(); |
| | | return BeanUtils.copyList(list, FieldCategoryVO.class); |
| | | } |
| | | } |