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.framework.model.validation.SelectGroup;
import com.jy.system.model.dto.SysDictDataDto;
import com.jy.system.model.dto.SysDictDataSelectDto;
import com.jy.system.model.vo.SysDictDataCacheVo;
import com.jy.system.model.vo.SysDictDataVo;
import com.jy.system.service.SysDictDataService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 字典数据 前端控制器
 * </p>
 *
 * @author
 * @since 2024-06-20
 */
@RestController
@RequestMapping("/sysDictData")
public class SysDictDataController {

    @Resource
    private SysDictDataService sysDictDataService;

    /**
     * 字典数据分页
     */
    @GetMapping("/getPage")
    public Page<SysDictDataVo> getPage(@Validated(SelectGroup.class) SysDictDataSelectDto dto) {
        return sysDictDataService.getPage(dto);
    }

    /**
     * 字典数据明细
     */
    @GetMapping("/getDetail")
    public SysDictDataVo getDetail(@Validated(DetailGroup.class) BaseSelectDto dto) {
        return sysDictDataService.getDetail(dto.getId());
    }

    /**
     * 字典数据新增
     */
    @JyLog(title = "新增字典数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public void add(@Validated(AddGroup.class) @RequestBody SysDictDataDto dto) {
        sysDictDataService.add(dto);
    }

    /**
     * 字典数据编辑
     */
    @JyLog(title = "编辑字典数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public void edit(@Validated(EditGroup.class) @RequestBody SysDictDataDto dto) {
        sysDictDataService.edit(dto);
    }

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

    /**
     * 通过字典类型获取明细列表
     */
    @GetMapping("/getListByCode")
    public List<SysDictDataCacheVo> getListByCode(@RequestParam("code") String code) {
        return sysDictDataService.getListByCode(code);
    }

}
