package com.finance.web.controller.api; import com.finance.common.basic.PageDTO; import com.finance.common.core.domain.R; import com.finance.common.exception.ServiceException; import com.finance.system.dto.FieldCategoryDTO; import com.finance.system.dto.ShowHideDTO; import com.finance.system.dto.update.FieldCategoryUpdateDTO; import com.finance.system.query.FieldCategoryQuery; import com.finance.system.service.TbFieldCategoryService; import com.finance.system.vo.FieldCategoryDetailVO; import com.finance.system.vo.FieldCategoryVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** *

* 字段分类表 前端控制器 *

* * @author mitao * @since 2024-03-13 */ @Slf4j @RestController @RequestMapping("/field-category") @RequiredArgsConstructor @Api(tags = "字段分类管理相关接口") public class TbFieldCategoryController { private final TbFieldCategoryService tbFieldCategoryService; /** * 添加 * * @param dto 字段分类数据传输对象 * @return R */ @PostMapping("/add") @ApiOperation("添加") public R add(@RequestBody @Validated FieldCategoryDTO dto) { try { tbFieldCategoryService.add(dto); } catch (Exception e) { if (e instanceof ServiceException) { return R.fail(e.getMessage()); } log.error("添加异常", e); return R.fail(); } return R.ok(); } /** * 根据id获取字段分类详情 * * @param id 字段分类id * @return R */ @GetMapping("/get-details") @ApiOperation("根据id获取字段分类详情") public R 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(); } } /** * 分页条件查询 * * @param query 部门条件查询对象 * @return PageVO */ @PostMapping("/page") @ApiOperation("分页条件查询") public R> page(@Validated @RequestBody FieldCategoryQuery 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 */ @PostMapping("/show-hide") @ApiOperation("隐藏显示操作") public R showHide(@RequestBody ShowHideDTO dto) { if (dto.getId() < 50) { throw new ServiceException("固定字段分类,不能操作!"); } 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(); } /** * 删除分类子节点 * * @param id id * @return R */ @DeleteMapping("/delete-children") @ApiOperation("编辑页面删除子字段分类") public R deleteChildren(@RequestParam(value = "id") Long id) { if (id < 50) { throw new ServiceException("固定字段分类,不能操作!"); } try { tbFieldCategoryService.deleteChildren(id); } catch (Exception e) { if (e instanceof ServiceException) { return R.fail(e.getMessage()); } log.error("编辑页面删除子字段分类异常", e); return R.fail(); } return R.ok(); } /** * 删除分类 * * @param id id * @return R */ @DeleteMapping("/delete") @ApiOperation("列表页面删除分类") public R delete(@RequestParam(value = "id") Long id) { if (id < 50) { throw new ServiceException("固定字段分类,不能操作"); } 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(); } /** * 编辑分类 * * @param dto 字段分类更新数据传输对象 * @return R */ @PutMapping("/edit") @ApiOperation("编辑") public R edit(@RequestBody FieldCategoryUpdateDTO dto) { if (dto.getId() < 50) { throw new ServiceException("固定字段分类,不能操作"); } 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(); } }