DictionaryController.java 2.53 KB
package vion.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.dto.DictionaryDTO;
import vion.dto.DictionaryTypeDTO;
import vion.model.Dictionary;
import vion.model.DictionaryType;
import vion.service.IDictionaryService;
import vion.service.IDictionaryTypeService;

@RestController
@RequestMapping(Global.BASE_URL)
@RequiredArgsConstructor
@Slf4j
public class DictionaryController {

    private final IDictionaryService dictionaryService;
    private final IDictionaryTypeService dictionaryTypeService;
    private final Converter converter;

    @GetMapping("/dictionarys")
    @SaCheckPermission(value = "dict:list", orRole="admin")
    public Page<Dictionary> getDictionaryList(DictionaryDTO data) {
        return dictionaryService.lambdaQuery(converter.convert(data, new Dictionary()))
                .page(Page.of(data.getPageNum(), data.getPageSize()));
    }

    @GetMapping("/dictionary")
    @SaCheckPermission(value = "dict:query", orRole="admin")
    public Object getDictionaryByID(@RequestParam(name = "id") Integer id) {
        return dictionaryService.getById(id);
    }

    @PostMapping("/dictionary")
    @SaCheckPermission(value = "dict:editAndSave", orRole="admin")
    public String saveOrUpdateDictionary(@RequestBody DictionaryDTO data) {
        Dictionary dictionary = converter.convert(data, new Dictionary());
        return dictionaryService.saveOrUpdate(dictionary) ? "成功" : "失败";
    }

    @GetMapping("/dictionaryTypes")
    @SaCheckPermission("dict:type:list")
    public Page<DictionaryType> getDictionaryTypeList(DictionaryTypeDTO data) {
        return dictionaryTypeService.lambdaQuery(converter.convert(data, new DictionaryType()))
                .page(Page.of(data.getPageNum(), data.getPageSize()));
    }

    @GetMapping("/dictionaryType")
    @SaCheckPermission("dict:type:query")
    public Object getDictionaryTypeByID(@RequestParam Integer id) {
        return dictionaryTypeService.getById(id);
    }

    @PostMapping("/dictionaryType")
    @SaCheckPermission("dict:type:editAndSave")
    public String saveOrUpdateDictionaryType(@RequestBody DictionaryTypeDTO data) {
        DictionaryType dictionaryType = converter.convert(data, new DictionaryType());
        return dictionaryTypeService.saveOrUpdate(dictionaryType) ? "成功" : "失败";
    }
}