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.common.utils.BeanUtils;
|
import com.finance.system.domain.TbBasicDataCategory;
|
import com.finance.system.dto.BasicDataCategoryDTO;
|
import com.finance.system.dto.ShowHideDTO;
|
import com.finance.system.dto.update.BasicDataCategoryUpdateDTO;
|
import com.finance.system.query.BasicDataCategoryQuery;
|
import com.finance.system.service.TbBasicDataCategoryService;
|
import com.finance.system.vo.BasicDataCategoryVO;
|
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.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
/**
|
* <p>
|
* 基础数据分类表 前端控制器
|
* </p>
|
*
|
* @author mitao
|
* @since 2024-03-13
|
*/
|
@Slf4j
|
@RestController
|
@RequiredArgsConstructor
|
@Api(tags = {"基础数据分类相关接口"})
|
@RequestMapping("/basic-data-category")
|
public class TbBasicDataCategoryController {
|
|
private final TbBasicDataCategoryService tbBasicDataCategoryService;
|
|
/**
|
* 添加
|
*
|
* @param dto 基础数据分类传输对象
|
* @return R<Void>
|
*/
|
@PostMapping("/add")
|
@ApiOperation("添加")
|
public R<Void> add(@RequestBody @Validated BasicDataCategoryDTO dto) {
|
try {
|
tbBasicDataCategoryService.add(dto);
|
} 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<Void>
|
*/
|
@PostMapping("/edit")
|
@ApiOperation("编辑")
|
public R<Void> add(@RequestBody @Validated BasicDataCategoryUpdateDTO dto) {
|
if (dto.getId() <= 17) {
|
throw new ServiceException("该基础数据分类不能修改");
|
}
|
try {
|
tbBasicDataCategoryService.update(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<Void>
|
*/
|
@DeleteMapping("/delete")
|
@ApiOperation("删除")
|
public R<Void> delete(@RequestParam(value = "id") Long id) {
|
if (id <= 17) {
|
throw new ServiceException("该基础数据分类不能删除");
|
}
|
try {
|
tbBasicDataCategoryService.removeById(id);
|
} 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<BasicDataCategoryVO>
|
*/
|
@GetMapping("/get-details")
|
@ApiOperation("根据id获取详情")
|
public R<BasicDataCategoryVO> getDetails(@RequestParam(value = "id") Long id) {
|
try {
|
TbBasicDataCategory basicDataCategory = tbBasicDataCategoryService.getById(id);
|
BasicDataCategoryVO vo = BeanUtils.copyBean(basicDataCategory,
|
BasicDataCategoryVO.class);
|
return R.ok(vo);
|
} catch (Exception e) {
|
if (e instanceof ServiceException) {
|
return R.fail(e.getMessage());
|
}
|
log.error("根据id获取详情异常", e);
|
return R.fail();
|
}
|
}
|
|
/**
|
* 隐藏显示操作
|
*
|
* @param dto 显示隐藏操作数据传输对象
|
* @return R<Void>
|
*/
|
@PostMapping("/show-hide")
|
@ApiOperation("隐藏显示操作")
|
public R<Void> showHide(@RequestBody ShowHideDTO dto) {
|
if (dto.getId() <= 17) {
|
throw new ServiceException("该基础数据分类不能隐藏");
|
}
|
try {
|
tbBasicDataCategoryService.showHide(dto);
|
} catch (Exception e) {
|
if (e instanceof ServiceException) {
|
return R.fail(e.getMessage());
|
}
|
log.error("隐藏显示操作异常", e);
|
return R.fail();
|
}
|
return R.ok();
|
}
|
|
/**
|
* 分页条件查询
|
*
|
* @param query 基础数据分类条件查询对象
|
* @return R<PageDTO < BasicDataCategoryVO>>
|
*/
|
@PostMapping("/page")
|
@ApiOperation("分页条件查询")
|
public R<PageDTO<BasicDataCategoryVO>> page(
|
@Validated @RequestBody BasicDataCategoryQuery query) {
|
try {
|
return R.ok(tbBasicDataCategoryService.queryPage(query));
|
} catch (Exception e) {
|
if (e instanceof ServiceException) {
|
return R.fail(e.getMessage());
|
}
|
log.error("分页条件查询异常", e);
|
return R.fail();
|
}
|
}
|
}
|