package com.backendsys.modules.system.controller;

import com.backendsys.modules.common.aspect.SysLog;
import com.backendsys.modules.common.utils.Result;
import com.backendsys.modules.system.entity.SysCommon;
import com.backendsys.modules.system.entity.SysLogEntity;
import com.backendsys.modules.system.service.SysCommonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RestController
@Tag(name = "系统配置")
public class SysCommonController {

    @Autowired
    private SysCommonService sysCommonService;

    @Operation(summary = "获取系统配置列表")
    @PreAuthorize("@sr.hasPermission('6.1')")
    @GetMapping("/api/system/common/getCommonList")
    public Result getCommonList(String category) {
        return Result.success().put("data", sysCommonService.selectCommonList(category));
    }

    @Operation(summary = "获取系统配置详情")
    @PreAuthorize("@sr.hasPermission('6.1.1')")
    @GetMapping("/api/system/common/getCommonDetail")
    public Result getCommonDetail(@Validated(SysCommon.Detail.class) SysCommon sysCommon) {
        return Result.success().put("data", sysCommonService.selectCommonDetail(sysCommon));
    }

    @SysLog("编辑系统配置")
    @Operation(summary = "编辑系统配置")
    @PreAuthorize("@sr.hasPermission('6.1.3')")
    @PutMapping("/api/system/common/updateCommon")
    public Result updateCommon(@Validated(SysCommon.Update.class) @RequestBody SysCommon sysCommon) {
        return Result.success().put("data", sysCommonService.updateCommon(sysCommon));
    }

//    // 测试后删除
//    @GetMapping("/api/system/common/getCommonValue")
//    public Object getCommonValue(Long id) {
//        return sysCommonService.getCommonValue(id);
//    }

}
