package com.css.simulation.resource.server.adapter.controller.system_manage.parameter_manage;

import api.common.pojo.common.ResponseBodyVO;
import api.common.pojo.param.system.ParameterParam;
import api.common.pojo.po.system.ParameterPO;
import api.common.pojo.vo.system.ParameterVO;
import api.common.util.ObjectUtil;
import com.css.simulation.resource.server.app.service.ParameterService;
import com.github.pagehelper.PageInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;


@RestController
@RequestMapping("/parameter")
@PreAuthorize("@AuthorityCheck.admin()")
public class ParameterController {

    @Resource
    private ParameterService parameterService;


    /**
     * 查询参数列表
     */
    @RequestMapping("/getParameterList")
    public ResponseBodyVO<PageInfo<ParameterVO>> getParameterList(@RequestBody ParameterParam pageParam) {
        ResponseBodyVO<PageInfo<ParameterVO>> response = new ResponseBodyVO<PageInfo<ParameterVO>>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(parameterService.getParameterList(pageParam));
        return response;
    }

    /**
     * 新增、修改
     */
    @RequestMapping("/saveParameter")
    public ResponseBodyVO<ParameterPO> saveParameter(@RequestBody ParameterPO parameterPO) {
        if (ObjectUtil.isNull(parameterPO)) {
            return new ResponseBodyVO(false, 400, "参数必传！", null);
        }
        ResponseBodyVO<ParameterPO> response = new ResponseBodyVO<ParameterPO>(ResponseBodyVO.Response.SUCCESS);
        parameterPO = parameterService.saveParameter(parameterPO);
        response.setInfo(parameterPO);
        return response;
    }

    /**
     * 查询参数修改历史记录
     */
    @RequestMapping("/getParamHistory")
    public ResponseBodyVO<PageInfo<ParameterVO>> getParamHistory(@RequestBody ParameterParam pageParam) {
        ResponseBodyVO<PageInfo<ParameterVO>> response = new ResponseBodyVO<PageInfo<ParameterVO>>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(parameterService.getParamHistory(pageParam));
        return response;
    }

    /**
     * 查询场景分配配置信息
     */
    @RequestMapping("/getSceneParam")
    public ResponseBodyVO<HashMap<String, Integer>> getSceneParam() {
        ResponseBodyVO<HashMap<String, Integer>> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
        HashMap<String, Integer> sceneParam = parameterService.getSceneParam();
        response.setInfo(sceneParam);
        return response;
    }

}
