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.SysConfigDto;
import com.jy.system.model.dto.SysConfigSelectDto;
import com.jy.system.model.vo.SysConfigVo;
import com.jy.system.service.SysConfigService;
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("/sysConfig")
public class SysConfigController {

    @Resource
    private SysConfigService sysConfigService;

    /**
     * 全局配置分页
     */
    @GetMapping("/getPage")
    public Page<SysConfigVo> getPage(SysConfigSelectDto dto) {
        return sysConfigService.getPage(dto);
    }

    /**
     * 全局配置明细
     */
    @GetMapping("/getDetail")
    public SysConfigVo getDetail(@Validated(DetailGroup.class) BaseSelectDto dto) {
        return sysConfigService.getDetail(dto.getId());
    }

    /**
     * 全局配置新增
     */
    @JyLog(title = "新增全局配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public void add(@Validated(AddGroup.class) @RequestBody SysConfigDto dto) {
        sysConfigService.add(dto);
    }

    /**
     * 全局配置编辑
     */
    @JyLog(title = "编辑全局配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public void edit(@Validated(EditGroup.class) @RequestBody SysConfigDto dto) {
        sysConfigService.edit(dto);
    }

    /**
     * 全局配置删除
     */
    @JyLog(title = "删除全局配置", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public void delete(@Validated(BatchDeleteGroup.class) @RequestBody BaseSelectDto dto) {
        sysConfigService.delete(dto.getIdList());
    }

    /**
     * 刷新全局配置缓存
     */
    @PostMapping("/refreshCache")
    public void refreshCache() {
        sysConfigService.refreshCache();
    }

}
