package com.tuoheng.admin.controller;

import cn.hutool.core.util.ObjectUtil;
import com.tuoheng.common.utils.JsonResult;
import com.tuoheng.common.utils.RedisUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/common")
@ApiOperation(value = "系统参数")
public class ParamController {


    @Autowired
    private RedisUtils redisUtils;


    @PutMapping("/status")
    @ApiOperation(value = "修改参数是否从硬件读取", notes = "修改参数是否从硬件读取")
    public JsonResult<Boolean> commonParam() {
        if(ObjectUtil.isEmpty(redisUtils.get("status"))){
            redisUtils.set("status",1);
        }else{
            int status=(Integer) redisUtils.get("status");
            status = status == 1 ? 2 : 1;
            redisUtils.set("status",status);
        }
        boolean status = (Integer) redisUtils.get("status") == 1;
        return JsonResult.success(status);
    }

}
