| | |
| | | |
| | | import com.ruoyi.common.basic.PageDTO; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.utils.BeanUtils; |
| | | import com.ruoyi.system.domain.TbFieldCategory; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.system.dto.FieldCategoryDTO; |
| | | import com.ruoyi.system.dto.ShowHideDTO; |
| | | import com.ruoyi.system.dto.update.FieldCategoryUpdateDTO; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | try { |
| | | tbFieldCategoryService.add(dto); |
| | | } catch (Exception e) { |
| | | log.error("添加分类异常", e); |
| | | throw new RuntimeException("操作失败"); |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("添加异常", e); |
| | | return R.fail(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | |
| | | * @param id 字段分类id |
| | | * @return R |
| | | */ |
| | | @GetMapping("/getById") |
| | | @GetMapping("/get-details") |
| | | @ApiOperation("根据id获取字段分类详情") |
| | | public R<FieldCategoryDetailVO> getById(@RequestParam(value = "id") Integer id) { |
| | | TbFieldCategory oneCategory = tbFieldCategoryService.getById(id); |
| | | if (Objects.isNull(oneCategory)) { |
| | | return R.ok(new FieldCategoryDetailVO()); |
| | | public R<FieldCategoryDetailVO> getById(@RequestParam(value = "id") Long id) { |
| | | try { |
| | | FieldCategoryDetailVO vo = tbFieldCategoryService.getDetailsById(id); |
| | | return R.ok(vo); |
| | | } catch (Exception e) { |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("根据id获取字段分类详情异常", e); |
| | | return R.fail(); |
| | | } |
| | | FieldCategoryDetailVO vo = BeanUtils.copyBean(oneCategory, FieldCategoryDetailVO.class); |
| | | //根据一级分类id,查询二级分类 |
| | | List<TbFieldCategory> twoCategoryList = tbFieldCategoryService.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 = tbFieldCategoryService.lambdaQuery().eq(TbFieldCategory::getParentId, item.getId()).list(); |
| | | threeCategoryList.forEach(threeCategory->{ |
| | | FieldCategoryDetailVO threeCategoryVO = BeanUtils.copyBean(threeCategory, FieldCategoryDetailVO.class); |
| | | twoCategoryVO.getChildren().add(threeCategoryVO); |
| | | }); |
| | | }); |
| | | return R.ok(vo); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PostMapping("/page") |
| | | @ApiOperation("分页条件查询") |
| | | public R<PageDTO<FieldCategoryVO>> page(@RequestBody FieldCategoryQuery query) { |
| | | return R.ok(tbFieldCategoryService.queryPage(query)); |
| | | try { |
| | | return R.ok(tbFieldCategoryService.queryPage(query)); |
| | | } catch (Exception e) { |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("分页条件查询异常", e); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param dto 显示隐藏操作数据传输对象 |
| | | * @return R |
| | | */ |
| | | @PutMapping("/show-hide") |
| | | @PostMapping("/show-hide") |
| | | @ApiOperation("隐藏显示操作") |
| | | public R<Object> showHide(@RequestBody ShowHideDTO dto) { |
| | | tbFieldCategoryService.showHide(dto); |
| | | public R<Void> showHide(@RequestBody ShowHideDTO dto) { |
| | | try { |
| | | tbFieldCategoryService.showHide(dto); |
| | | } catch (Exception e) { |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("隐藏显示操作异常", e); |
| | | return R.fail(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @DeleteMapping("/delete-children") |
| | | @ApiOperation("编辑页面删除子字段分类") |
| | | public R<Object> deleteChildren(@RequestParam(value = "id") Integer id){ |
| | | public R<Object> deleteChildren(@RequestParam(value = "id") Long id){ |
| | | try { |
| | | tbFieldCategoryService.deleteChildren(id); |
| | | } catch (Exception e) { |
| | | log.error("编辑页面删除子字段分类失败",e); |
| | | throw new RuntimeException("操作失败"); |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("编辑页面删除子字段分类异常", e); |
| | | return R.fail(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | |
| | | */ |
| | | @DeleteMapping("/delete") |
| | | @ApiOperation("列表页面删除分类") |
| | | public R<Void> delete(@RequestParam(value = "id") Integer id){ |
| | | tbFieldCategoryService.delete(id); |
| | | public R<Void> delete(@RequestParam(value = "id") Long id){ |
| | | try { |
| | | tbFieldCategoryService.delete(id); |
| | | } catch (Exception e) { |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("列表页面删除分类异常", e); |
| | | return R.fail(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | @PutMapping("/edit") |
| | | @ApiOperation("编辑") |
| | | public R<Object> edit(@RequestBody FieldCategoryUpdateDTO dto) { |
| | | tbFieldCategoryService.edit(dto); |
| | | try { |
| | | tbFieldCategoryService.edit(dto); |
| | | } catch (Exception e) { |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("编辑异常", e); |
| | | return R.fail(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |