package com.sunyard.ssp.modules.sysconf.cipherunit.controller;

import com.sunyard.chsm.model.entity.ParamConf;
import com.sunyard.ssp.common.Result;
import com.sunyard.ssp.modules.sysconf.paramconf.service.IParamConfService;
import com.sunyard.ssp.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Slf4j
@Api(description = "密码部件管理接口", tags = "全局密码模块状态显示")
@RequestMapping("/status")
public class StatusController {
    @Autowired
    IParamConfService iParamConfService;

//    @ControllerLog("获取全局密码模块状态")
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取密码模块状态")
    public Result<Object> queryStatus() {
        /*
         * status = 0 初始化状态; status = 1 密码主管状态;  status = 2 密码主管状态; status = 3 自测试状态; status = 4 错误报警状态;
         * status = 5 核准状态; status = 6 关键参数输入状态;status = 7 核准状态
         */
        ParamConf status = iParamConfService.selectByKey("status");
        return new ResultUtil<Object>().setData(status.getValue());
    }

//    @ControllerLog("修改全局密码模块状态")
    @RequestMapping(value = "/set", method = RequestMethod.PUT)
    @ResponseBody
    @ApiOperation(value = "修改密码模块状态")
    public Result<Object> setStatus(@RequestParam("value") String value) {
        ParamConf status = iParamConfService.selectByKey("status");
        status.setValue(value);
        iParamConfService.updateById(status);
        return new ResultUtil<Object>().setData(status.getValue());
    }
}
