package com.hdkj.lt.bf.controller.optimization;

import com.alibaba.fastjson.JSON;
import com.hdkj.fhzg.optimization.request.FeederGroupRequest;
import com.hdkj.fhzg.optimization.request.FeederMetricsRequest;
import com.hdkj.fhzg.optimization.response.FeederGroupMetrics;
import com.hdkj.fhzg.optimization.response.FeederMetrics;
import com.hdkj.hussar.ApiResponse;
import com.hdkj.lt.bf.application.OptimizationApplication;
import com.hdkj.lt.bf.entity.vo.XlRelVO;
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;

/**
 * @author rj
 * @date 2026/5/22 17:18
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/optimization")
@RequiredArgsConstructor
public class OptimizationController {

    private final OptimizationApplication optimizationApplication;


    /**
     * 获取接线组指标数据
     *
     * @return
     */
    @PostMapping("/getFeederGroupMetrics")
    public ApiResponse<FeederGroupMetrics> getFeederGroupMetrics(@RequestBody FeederGroupRequest request) {
        String json = "{\n" +
                "  \"operationIssue\": {\n" +
                "    \"operationIssueScore\": 0.00,\n" +
                "    \"overloadLineCount\": 0,\n" +
                "    \"avgLoadRate\": 0.00,\n" +
                "    \"voltageViolationNodeCount\": 0,\n" +
                "    \"stationN1FailCount\": 0,\n" +
                "    \"feederN1FailCount\": 0,\n" +
                "    \"lineN1PassRate\": 0.00\n" +
                "  },\n" +
                "  \"reliability\": {\n" +
                "    \"reliabilityScore\": 0.00,\n" +
                "    \"theoreticalReliability\": 0.00,\n" +
                "    \"outageLineCount\": 0.00,\n" +
                "    \"outageTransformerCount\": 0.00,\n" +
                "    \"affectedLowVoltageUserCount\": 0.00,\n" +
                "    \"importantSensitiveUserLossCount\": 0.00\n" +
                "  },\n" +
                "  \"networkLossImpact\": {\n" +
                "    \"networkLossImpactScore\": 0.00,\n" +
                "    \"totalNetworkLoss\": 0.00,\n" +
                "    \"networkLossNonCompliantCount\": 0.00,\n" +
                "    \"networkLossCompliantRate\": 0.00,\n" +
                "    \"powerFactorNonCompliantLineCount\": 0.00\n" +
                "  },\n" +
                "  \"networkStructureIssue\": {\n" +
                "    \"networkStructureIssueScore\": 0.00,\n" +
                "    \"singleRadiationLineCount\": 0.00,\n" +
                "    \"lineContactRate\": 0.00,\n" +
                "    \"complexContactLineCount\": 0.00,\n" +
                "    \"powerRadiusExceedLineCount\": 0.00,\n" +
                "    \"largeBranchCount\": 0.00,\n" +
                "    \"unreasonableSegmentCount\": 0.00,\n" +
                "    \"abnormalLoadGroupCount\": 0.00,\n" +
                "    \"excessiveInstalledCapacityCount\": 0.00,\n" +
                "    \"userExceed80Count\": 0.00\n" +
                "  }\n" +
                "}";
        FeederGroupMetrics feederGroupMetrics = JSON.parseObject(json, FeederGroupMetrics.class);
        return ApiResponse.success(feederGroupMetrics);
    }


    /**
     * 获取单线指标数据
     *
     * @return
     */
    @PostMapping("/getFeederMetrics")
    public ApiResponse<FeederMetrics> getFeederGroupMetrics(@RequestBody FeederMetricsRequest request) {
        String json = "{\n" +
                "  \"operationIssue\": {\n" +
                "    \"operationIssueScore\": 0.00,\n" +
                "    \"currentLineLoadRate\": 0.00,\n" +
                "    \"currentOverlimitSegmentCount\": 0,\n" +
                "    \"voltageViolationNodeCount\": 0,\n" +
                "    \"insufficientTransferCapacityLineCount\": 0,\n" +
                "    \"lineN1Check\": false\n" +
                "  },\n" +
                "  \"reliability\": {\n" +
                "    \"reliabilityScore\": 0.00,\n" +
                "    \"lineStatus\": \"Status_b\",\n" +
                "    \"outageTransformerCount\": 0.00,\n" +
                "    \"theoreticalReliability\": 0.00,\n" +
                "    \"affectedLowVoltageUserCount\": 0,\n" +
                "    \"importantSensitiveUserLossCount\": 0\n" +
                "  },\n" +
                "  \"networkLossImpact\": {\n" +
                "    \"networkLossImpactScore\": 0.00,\n" +
                "    \"activePowerLoss\": 0.00,\n" +
                "    \"lossRate\": 0.00,\n" +
                "    \"exportPowerFactor\": 0.00\n" +
                "  },\n" +
                "  \"networkStructureIssue\": {\n" +
                "    \"networkStructureIssueScore\": 0.00,\n" +
                "    \"lineConnectionType\": \"Type_f\",\n" +
                "    \"lineContactSwitchCount\": 0,\n" +
                "    \"totalInstalledCapacity\": 0.00,\n" +
                "    \"lineUserCount\": 0,\n" +
                "    \"abnormalLoadGroupCount\": \"Count_b\",\n" +
                "    \"loadGroupSegmentCount\": 0,\n" +
                "    \"largeBranchCount\": 0,\n" +
                "    \"linePowerSupplyRadius\": 0.00\n" +
                "  }\n" +
                "}";
        FeederMetrics feederMetrics = JSON.parseObject(json, FeederMetrics.class);
        return ApiResponse.success(feederMetrics);
    }




}
