package com.njcn.system.controller;


import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.system.pojo.po.Config;
import com.njcn.system.service.IConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.njcn.web.controller.BaseController;

import java.util.Objects;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2021-12-13
 */
@Slf4j
@Api(tags = "系统配置操作")
@RestController
@RequestMapping("/config")
@RequiredArgsConstructor
public class ConfigController extends BaseController {

    private final IConfigService iConfigService;


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getSysConfig")
    @ApiOperation("获取系统配置")
    public HttpResult<Config> getSysConfig() {
        String methodDescribe = getMethodDescribe("getSysConfig");
        LogUtil.njcnDebug(log, "{}", methodDescribe, methodDescribe);
        Config config = iConfigService.lambdaQuery()
                .eq(Config::getState, DataStateEnum.ENABLE.getCode())
                .one();
        if (Objects.isNull(config)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, config, methodDescribe);
        }
    }


}

