mitao
2024-04-10 2da6576ce17cb18f042f561648230736945ec4c1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbBasicDataCategoryController.java
@@ -3,6 +3,7 @@
import com.ruoyi.common.basic.PageDTO;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.BeanUtils;
import com.ruoyi.system.domain.TbBasicDataCategory;
import com.ruoyi.system.dto.BasicDataCategoryDTO;
@@ -17,8 +18,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;
/**
 * <p>
@@ -45,7 +44,15 @@
    @PostMapping("/add")
    @ApiOperation("添加")
    public R<Void> add(@RequestBody @Validated BasicDataCategoryDTO dto) {
        tbBasicDataCategoryService.add(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();
    }
@@ -57,7 +64,15 @@
    @PostMapping("/edit")
    @ApiOperation("编辑")
    public R<Void> add(@RequestBody @Validated BasicDataCategoryUpdateDTO dto) {
        tbBasicDataCategoryService.update(dto);
        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();
    }
@@ -69,7 +84,15 @@
    @DeleteMapping("/delete")
    @ApiOperation("删除")
    public R<Void> delete(@RequestParam(value = "id") Integer id){
        tbBasicDataCategoryService.removeById(id);
        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();
    }
@@ -81,9 +104,17 @@
    @GetMapping("/get-details")
    @ApiOperation("根据id获取详情")
    public R<BasicDataCategoryVO> getDetails(@RequestParam(value = "id") Integer id){
        TbBasicDataCategory basicDataCategory = tbBasicDataCategoryService.getById(id);
        BasicDataCategoryVO vo = BeanUtils.copyBean(basicDataCategory, BasicDataCategoryVO.class);
        return R.ok(vo);
        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();
        }
    }
    /**
@@ -94,11 +125,15 @@
    @PostMapping("/show-hide")
    @ApiOperation("隐藏显示操作")
    public R<Void> showHide(@RequestBody ShowHideDTO dto) {
        TbBasicDataCategory basicDataCategory = tbBasicDataCategoryService.getById(dto.getId());
        if (Objects.isNull(basicDataCategory)) {
            throw new RuntimeException("非法参数");
        try {
            tbBasicDataCategoryService.showHide(dto);
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("隐藏显示操作异常", e);
            return R.fail();
        }
        tbBasicDataCategoryService.lambdaUpdate().set( TbBasicDataCategory::getStatus, dto.getStatus()).eq(TbBasicDataCategory::getId, dto.getId()).update();
        return R.ok();
    }
@@ -109,9 +144,16 @@
     */
    @PostMapping("/page")
    @ApiOperation("分页条件查询")
    public R<PageDTO<BasicDataCategoryVO>> page(@RequestBody BasicDataCategoryQuery query) {
        return R.ok(tbBasicDataCategoryService.queryPage(query));
    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();
        }
    }
}