package com.kym.miniapp.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.annotation.SaMode;
import com.kym.common.R;
import com.kym.common.controller.IController;
import com.kym.entity.DataDict;
import com.kym.service.DataDictService;
import jakarta.annotation.Resource;
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;

import java.util.List;


/**
 * <p>
 * 数据字典 前端控制器
 * </p>
 * <ul>
 *     <li>字典以常量形式定义在业务实体类中，业务逻辑以常量替代，取消魔法值</li>
 *     <li>字典只提供查询接口，修改、新增由数据库DML执行实现</li>
 *     <li>为保持与前端及关联系统一致，字典定义后不可修改，不可删除，可废弃</li>
 * </ul>
 *
 * @author zuy
 * @since 2023-08-13
 */
@RestController
@RequestMapping("/dict")
public class DataDictController extends IController {

    @Resource
    private DataDictService dataDictService;

    /**
     * 字典列表
     */
    @SaIgnore
    @PostMapping("list")
    public R<?> list(@RequestBody DataDict query) {
        return resp(() -> dataDictService.list(query));
    }



    @SaCheckPermission(value = {"dict.add", "dict.modify"}, mode = SaMode.OR)
    @PostMapping("saveOrUpdate")
    public R<?> saveOrUpdate(@RequestBody List<DataDict> dictList) {
        return resp((t) -> dataDictService.saveOrUpdate(dictList));
    }


}
