package com.xzzn.web.controller.ems;

import com.xzzn.common.core.controller.BaseController;
import com.xzzn.common.core.domain.AjaxResult;
import com.xzzn.common.utils.StringUtils;
import com.xzzn.ems.domain.EmsStrategyRuntimeConfig;
import com.xzzn.ems.service.IEmsStrategyRuntimeConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 策略运行参数配置Controller
 */
@RestController
@RequestMapping("/system/strategyRuntimeConfig")
public class EmsStrategyRuntimeConfigController extends BaseController {

    @Autowired
    private IEmsStrategyRuntimeConfigService runtimeConfigService;

    /**
     * 按站点ID获取策略运行参数
     */
    @GetMapping("/getBySiteId")
    public AjaxResult getBySiteId(String siteId) {
        if (StringUtils.isEmpty(siteId)) {
            return error("缺少必填字段siteId");
        }
        return success(runtimeConfigService.getBySiteId(siteId));
    }

    /**
     * 保存策略运行参数（按siteId新增/更新）
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody EmsStrategyRuntimeConfig config) {
        if (config == null || StringUtils.isEmpty(config.getSiteId())) {
            return error("缺少必填字段siteId");
        }
        config.setCreateBy(getUsername());
        config.setUpdateBy(getUsername());
        return toAjax(runtimeConfigService.saveBySiteId(config));
    }
}
