mitao
2024-04-09 ec76c5defdd8018ce4efcc8795508498a84de4b7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbFieldController.java
@@ -16,12 +16,17 @@
import com.ruoyi.system.vo.FieldVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
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>
@@ -39,15 +44,16 @@
public class TbFieldController {
    private final TbFieldService tbFieldService;
    private final TbFieldCategoryService  tbFieldCategoryService;
    private final TbFieldCategoryService tbFieldCategoryService;
    /**
     * 获取分类列表
     *
     * @param id 分类id
     * @return 分类列表
     */
    @GetMapping("/categories")
    @ApiOperation(value = "获取分类列表",notes = "一级分类id传0,二级分类传一级分类id,三级分类同理")
    @ApiOperation(value = "获取分类列表", notes = "一级分类id传0,二级分类传一级分类id,三级分类同理")
    public R<List<FieldCategoryVO>> queryFieldCategories(@RequestParam Long id) {
        try {
            return R.ok(tbFieldCategoryService.queryFieldCategories(id));
@@ -62,12 +68,13 @@
    /**
     * 添加字段
     *
     * @param dto 字段数据传输对象
     * @return 响应状态
     */
    @PostMapping("/add")
    @ApiOperation("添加字段")
    public R<Void> add(@RequestBody @Validated FieldDTO dto){
    public R<Void> add(@RequestBody @Validated FieldDTO dto) {
        try {
            tbFieldService.add(dto);
        } catch (Exception e) {
@@ -93,8 +100,10 @@
            return R.fail();
        }
    }
    /**
     * 隐藏显示操作
     *
     * @param dto 显示隐藏操作数据传输对象
     * @return R
     */
@@ -115,12 +124,13 @@
    /**
     * 编辑字段
     *
     * @param dto 字段数据传输对象
     * @return 响应状态
     */
    @PostMapping("/edit")
    @ApiOperation("编辑字段")
    public R<Void> add(@RequestBody @Validated FieldUpdateDTO dto){
    public R<Void> add(@RequestBody @Validated FieldUpdateDTO dto) {
        try {
            tbFieldService.update(dto);
        } catch (Exception e) {
@@ -135,6 +145,7 @@
    /**
     * 分页条件查询
     *
     * @param query 部门条件查询对象
     * @return PageVO<FieldCategoryDetailVO>
     */
@@ -154,12 +165,13 @@
    /**
     * 获取详情
     *
     * @param id id
     * @return FieldVO
     */
    @GetMapping("/get-details")
    @ApiOperation("获取详情")
    public R<FieldVO> getDetails(@RequestParam Long id){
    public R<FieldVO> getDetails(@RequestParam Long id) {
        try {
            TbField field = tbFieldService.getById(id);
            return R.ok(BeanUtils.copyBean(field, FieldVO.class));
@@ -174,12 +186,13 @@
    /**
     * 删除
     *
     * @param id id
     * @return 响应状态
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除")
    public R<Void> delete(@RequestParam Long id){
    public R<Void> delete(@RequestParam Long id) {
        try {
            tbFieldService.removeById(id);
        } catch (Exception e) {
@@ -191,5 +204,19 @@
        }
        return R.ok();
    }
    /**
     * 模板下载
     */
    @GetMapping("/download")
    @ApiOperation("模板下载")
    public void downloadImportTemplate() {
        try {
            tbFieldService.downloadImportTemplate();
        } catch (Exception e) {
            log.error("模板下载异常", e);
            throw new ServiceException("模板下载失败,请联系管理员!");
        }
    }
}