package com.hdkj.lt.mq.controller;

import cn.hutool.json.JSONObject;
import com.hdkj.lt.core.mvc.BaseController;
import com.hdkj.lt.mq.entity.dto.BrakerScopeDTO;
import com.hdkj.lt.mq.service.plan.FhzgReasoningPlatformService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

import java.util.List;
import java.util.Map;

/**
 * 查询停电范围的 开关段
 *
 * @author zhuzhe
 * @since 2025-05-12
 */
@Slf4j
@RestController
@RequestMapping("/fhzgReasoningPlatform")
@RequiredArgsConstructor
public class FhzgReasoningPlatformController extends BaseController {

    private final FhzgReasoningPlatformService planReasoningPlatform;

    /**
     * 获取停电区域列表
     *
     * @param message
     * @return
     */
    @PostMapping("/getPowerOutAreaList")
    @ApiOperation(value = "解析计划停电传入停电信息解析停电区域")
    public List<BrakerScopeDTO> getPowerOutAreaList(@RequestBody String message) {
        //JSONObject jsonObject = new JSONObject(message);
        //Long planIdL = jsonObject.getLong("planId");
        Long planIdL = Long.valueOf(message);
        List<BrakerScopeDTO> breakerList = planReasoningPlatform.getPowerOutAreaList(planIdL);
        return breakerList;
    }

    /**
     * 获取停电区域配变
     *
     * @param device
     * @return
     */
    @PostMapping("/getBreakerTransformerBySwitch")
    @ApiOperation(value = "查询停电区域配变")
    public Map<String, List<String>> getBreakerTransformerBySwitch(@RequestBody String device) {
        JSONObject jsonObject = new JSONObject(device);
        String startSwitch = jsonObject.getStr("startSwitch");
        String endSwitchStr = jsonObject.getStr("endSwitch");
        String feeder = jsonObject.getStr("feeder");
        Map<String, List<String>> breakerTransformerMap = planReasoningPlatform.getBreakerTransformerBySwitch(startSwitch, endSwitchStr, feeder);
        return breakerTransformerMap;
    }

}
