/*
 * 文 件 名:  InDoorEnergyController
 * 版    权:  华设设计集团股份有限公司
 * 描    述:  <描述>
 * 修 改 人:  lvwenbin
 * 修改时间:  2025/8/18
 * 跟踪单号:  <跟踪单号>
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */
package com.ruoyi.ems.controller;

import com.ruoyi.ems.handle.BaCtlHandler;
import com.ruoyi.ems.model.AbilityPayload;
import com.ruoyi.ems.model.CallResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 楼宇采集控制Api
 * <功能详细描述>
 *
 * @author lvwenbin
 * @version [版本号, 2025/8/18]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@RestController
@CrossOrigin(allowedHeaders = "*", allowCredentials = "false")
@RequestMapping("/ba")
@Api(value = "InDoorEnergyController", description = "楼宇采集控制Api")
public class BaCtlController {
    /**
     * 日志
     */
    private static final Logger log = LoggerFactory.getLogger(BaCtlController.class);

    @Qualifier("baCtlHandler")
    @Resource
    private BaCtlHandler baCtlHandler;

    /**
     * 常泰室内能耗能力调用
     *
     * @return 数据列表
     */
    @RequestMapping(value = "/ct/abilityCall", method = RequestMethod.POST)
    @ApiOperation(value = "/ct/abilityCall", notes = "常泰BA能力调用")
    @ApiResponses({ @ApiResponse(code = 200, message = "success"),
        @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
    })
    public CallResponse<Void> ctAbilityCall(@RequestBody AbilityPayload abilityPayload) {
        CallResponse<Void> res = null;

        try {
            res = baCtlHandler.call(abilityPayload);
        }
        catch (Exception e) {
            log.error("ctAbilityCall fail!", e);
            res = new CallResponse<>(501, "内部错误:" + e.getMessage());
        }

        return res;
    }
}