package com.hdkj.lt.mq.controller;

import com.hdkj.lt.base.exception.BusinessException;
import com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferSchemeEvaluationIndex;
import com.hdkj.lt.core.bizms.modle.po.plan.PlanAwaitTransferAreaResultPO;
import com.hdkj.lt.modle.dto.jsty.XferPlanDTO;
import com.hdkj.lt.mq.service.base.impl.FhzgPlanSchemeScoreServiceImpl2;
import com.hdkj.lt.mq.service.fault.FaultTransferSchemeEvaluationIndexService;
import com.hdkj.lt.mq.service.plan.AnalysisPlanTransferSchemeService;
import com.hdkj.lt.mq.service.plan.PlanTransferSchemeEvaluationIndexService;
import com.hdkj.hussar.ApiResponse;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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 luorui
 * @date 2025/5/25 10:58
 */
@Slf4j
@RestController
@RequestMapping("test")
public class AnalysisPlanTransferSchemeController {
    @Autowired
    AnalysisPlanTransferSchemeService analysisPlanTransferSchemeService;
    @Autowired
    PlanTransferSchemeEvaluationIndexService planTransferSchemeEvaluationIndexService;
    @Autowired
    FhzgPlanSchemeScoreServiceImpl2 fhzgPlanSchemeScoreServiceImpl2;
    @Autowired
    FaultTransferSchemeEvaluationIndexService faultTransferSchemeEvaluationIndexService;

    /**
     * @author luorui
     * @date 2025/5/25 11:20
     * @discription 测试解析转供方案
     **/
    @PostMapping("/analysisPlanTransferScheme")
    @ApiOperation(value = "测试解析转供方案")
    public ApiResponse<Map<Long, XferPlanDTO>> getTransferSchemeOppositeLineLoadFactorByIdPage(@RequestBody PlanAwaitTransferAreaResultPO planAwaitTransferAreaResultPO) {
        Map<Long, XferPlanDTO> result = analysisPlanTransferSchemeService.analysis(planAwaitTransferAreaResultPO.getPlanId());
        return ApiResponse.success(result);
    }


    /**
     * @author luorui
     * @date 2025/5/28 14:29
     * @discription 测试推演平台数据全部落库后，收集算分所需数据保存到指标表
     **/
    @PostMapping("/saveSchemeEvaluationIndex")
    @ApiOperation(value = "测试推演平台数据全部落库后，收集算分所需数据保存到指标表")
    public ApiResponse<List<FhzgPlanTransferSchemeEvaluationIndex>> saveSchemeEvaluationIndex(@RequestBody PlanAwaitTransferAreaResultPO planAwaitTransferAreaResultPO) {
        List<FhzgPlanTransferSchemeEvaluationIndex> result = planTransferSchemeEvaluationIndexService.saveSchemeEvaluationIndex(planAwaitTransferAreaResultPO.getPlanId());
        return ApiResponse.success(result);
    }


    /**
     * @author luorui
     * @date 2025/5/28 14:29
     * @discription 测试评分
     **/
    @PostMapping("/score")
    @ApiOperation(value = "计划停电方案评分")
    public ApiResponse<String> score(@RequestBody PlanAwaitTransferAreaResultPO planAwaitTransferAreaResultPO) {
        Long planId = planAwaitTransferAreaResultPO.getPlanId();
        if (planId == null) {
            throw new BusinessException("参数为空planId");
        }
        //先删除数据
        planTransferSchemeEvaluationIndexService.deleteScoreData(planId);
        fhzgPlanSchemeScoreServiceImpl2.planScore(planId);
        return ApiResponse.success("评分成功");
    }


    /**
     * @author luorui
     * @date 2025/5/28 14:29
     * @discription 故障评分
     **/
    @PostMapping("/repairScore")
    @ApiOperation(value = "故障评分")
    public ApiResponse<String> repairScore(@RequestBody PlanAwaitTransferAreaResultPO planAwaitTransferAreaResultPO) {
        Long planId = planAwaitTransferAreaResultPO.getPlanId();
        if (planId == null) {
            throw new BusinessException("参数为空planId");
        }
        //先删除数据
        faultTransferSchemeEvaluationIndexService.deleteScoreData(planId);
        fhzgPlanSchemeScoreServiceImpl2.repairScore(planId);
        return ApiResponse.success("评分成功");
    }

}
