package com.jy.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.framework.model.annotation.JyLog;
import com.jy.framework.model.base.BaseSelectDto;
import com.jy.framework.model.enums.BusinessType;
import com.jy.framework.model.validation.AddGroup;
import com.jy.framework.model.validation.BatchDeleteGroup;
import com.jy.framework.model.validation.DetailGroup;
import com.jy.framework.model.validation.EditGroup;
import com.jy.system.model.dto.SysDictTypeDto;
import com.jy.system.model.dto.SysDictTypeSelectDto;
import com.jy.system.model.vo.SysDictTypeVo;
import com.jy.system.service.SysDictTypeService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
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.RestController;

/**
 * <p>
 * 字典类型 前端控制器
 * </p>
 *
 * @author
 * @since 2024-06-20
 */
@RestController
@RequestMapping("/sysDictType")
public class SysDictTypeController {

    @Resource
    private SysDictTypeService sysDictTypeService;

    /**
     * 字典类型分页
     */
    @GetMapping("/getPage")
    public Page<SysDictTypeVo> getPage(SysDictTypeSelectDto dto) {
        return sysDictTypeService.getPage(dto);
    }

    /**
     * 字典类型明细
     */
    @GetMapping("/getDetail")
    public SysDictTypeVo getDetail(@Validated(DetailGroup.class) BaseSelectDto dto) {
        return sysDictTypeService.getDetail(dto.getId());
    }

    /**
     * 字典类型新增
     */
    @JyLog(title = "新增字典类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public void add(@Validated(AddGroup.class) @RequestBody SysDictTypeDto dto) {
        sysDictTypeService.add(dto);
    }

    /**
     * 字典类型编辑
     */
    @JyLog(title = "编辑字典类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public void edit(@Validated(EditGroup.class) @RequestBody SysDictTypeDto dto) {
        sysDictTypeService.edit(dto);
    }

    /**
     * 字典类型删除
     */
    @JyLog(title = "删除字典类型", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public void delete(@Validated(BatchDeleteGroup.class) @RequestBody BaseSelectDto dto) {
        sysDictTypeService.delete(dto.getIdList());
    }

    /**
     * 刷新全局字典缓存
     */
    @PostMapping("/refreshCache")
    public void refreshCache() {
        sysDictTypeService.refreshCache();
    }

}
