package com.hdkj.lt.bf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdkj.lt.bf.entity.UsersPage;
import com.hdkj.lt.bf.entity.dto.*;
import com.hdkj.lt.bf.entity.vo.SectionTransferPage;
import com.hdkj.lt.bf.service.*;
import com.hdkj.lt.core.bizms.modle.dto.FhzgFaultTransferSchemePathDetailDTO;
import com.hdkj.lt.core.bizms.modle.dto.FhzgFaultTransferSchemeUsersReqDTO;
import com.hdkj.lt.core.bizms.modle.dto.FhzgPlanTransferSchemeAllSwitchDTO;
import com.hdkj.lt.core.bizms.modle.dto.FhzgPlanTransferSchemeUsersReqDTO;
import com.hdkj.lt.core.bizms.modle.po.fault.FaultTransferScheme;
import com.hdkj.lt.core.bizms.modle.po.fault.FaultTransferSchemeOppositeLineLoadFactor;
import com.hdkj.lt.core.bizms.modle.po.plan.FhzgFaultTransferSchemeFinalSegmentCurrentDetail;
import com.hdkj.lt.core.bizms.modle.po.plan.FhzgFaultTransferSchemeFinalSwitchCurrentDetail;
import com.hdkj.lt.modle.dto.jsty.AllSwitchInfoListDTO;
import com.hdkj.hussar.ApiResponse;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
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;

/**
 * @author luorui
 * @date 2025/5/14 15:18
 *
 * 故障停电方案控制器
 */
@RestController
@RequestMapping("/fhzgFaultTransferScheme")
@RequiredArgsConstructor
public class FhzgFaultTransferSchemeController {

    @Autowired
    IFaultTransferSchemeService faultTransferSchemeService;

    @Autowired
    IFaultTransferSchemePathDetailService faultTransferSchemePathDetailService;

    @Autowired
    IFaultTransferSchemeSwitchingSequenceService faultTransferSchemeSwitchingSequenceService;

    @Autowired
    FhzgFaultTransferSchemeFinalSwitchCurrentDetailService faultTransferSchemeFinalSwitchCurrentDetailService;

    @Autowired
    FhzgFaultTransferSchemeFinalSegmentCurrentDetailService faultTransferSchemeFinalSegmentCurrentDetailService;


    @Autowired
    IFaultTransferSchemeOppositeLineLoadFactorService fhzgPlanTransferSchemeOppositeLineLoadFactorService;

    @Autowired
    IFaultTransferSchemeUsersService faultTransferSchemeUsersService;

    /**
     * 故障停电转供方案列表查询接口
     * @param faultTransferSchemeListReqDTO
     * @return
     */
    @PostMapping("/getTransferSchemeListByFaultId")
    @ApiOperation(value = "停电计划转供方案列表查询接口")
    public ApiResponse<List<FhzgFaultTransferSchemeDTO>> getTransferSchemeListByPlanId(@RequestBody FhzgFaultTransferSchemeListReqDTO faultTransferSchemeListReqDTO) {
        FaultTransferScheme faultTransferScheme = new FaultTransferScheme();
        faultTransferScheme.setFaultId(faultTransferSchemeListReqDTO.getFaultId());
        faultTransferScheme.setSchemeType(faultTransferSchemeListReqDTO.getSchemeType());
        List<FhzgFaultTransferSchemeDTO> result = faultTransferSchemeService.getTransferSchemeListByFaultId(faultTransferScheme);
        return ApiResponse.success(result);
    }


    /**
     * 查询故障停电下的推荐方案和不通过方案数量
     * @param faultTransferSchemeListReqDTO
     * @return
     */
    @PostMapping("/getTransferSchemeCheckResultCountByFaultId")
    @ApiOperation(value = "推荐方案和不通过方案数量查询接口")
    public ApiResponse<List<FhzgFaultTransferSchemeCheckCountResultDTO>> getTransferSchemeCheckResultCountByPlanId(@RequestBody FhzgFaultTransferSchemeListReqDTO faultTransferSchemeListReqDTO) {
        FaultTransferScheme faultTransferScheme = new FaultTransferScheme();
        faultTransferScheme.setFaultId(faultTransferSchemeListReqDTO.getFaultId());
        List<FhzgFaultTransferSchemeCheckCountResultDTO> result = faultTransferSchemeService.getTransferSchemeCheckResultCountByFaultId(faultTransferScheme);
        return ApiResponse.success(result);
    }


    /**
     * 修改推荐方案的选定状态，一组方案中只能有一个方案为选定状态
     * @param fhzgFaultTransferSchemeUpdateReqDTO
     * @return
     */
    @PostMapping("/updateSchemeState")
    @ApiOperation(value = "修改推荐方案的选定状态，一组方案中只能有一个方案为选定状态")
    public ApiResponse<String> updateSchemeState(@RequestBody FhzgFaultTransferSchemeUpdateReqDTO fhzgFaultTransferSchemeUpdateReqDTO) {
        Integer result = faultTransferSchemeService.updateSchemeState(fhzgFaultTransferSchemeUpdateReqDTO);
        if (result > 0) {
            return ApiResponse.success("更新成功");
        } else {
            return ApiResponse.fail("更新失败");
        }
    }

    /**
     * 停电计划转供方案转供路径列表查询
     * @param faultTransferScheme
     * @return
     */
    @PostMapping("/getTransferSchemePathDetailBySchemeId")
    @ApiOperation(value = "根据组合方案id查询转供路径")
    public ApiResponse<SectionTransferPage<FhzgFaultTransferSchemePathDetailDTO>> getTransferSchemePathDetailBySchemeId(@RequestBody FaultTransferScheme faultTransferScheme) {
        SectionTransferPage<FhzgFaultTransferSchemePathDetailDTO> result = faultTransferSchemePathDetailService.getTransferSchemePathDetailBySchemeId(faultTransferScheme);
        return ApiResponse.success(result);
    }


    /**
     * 停电计划转供方案转供路径概述查询
     *
     * @param faultTransferScheme
     * @return
     */

    @PostMapping("/getTransferSchemePathDefinition")
    @ApiOperation(value = "查询转供路径概述")
    public ApiResponse<FhzgFaultTransferSchemePathDefinitionDTO> getTransferSchemePathDefinition(@RequestBody FaultTransferScheme faultTransferScheme) {
        FhzgFaultTransferSchemePathDefinitionDTO result = faultTransferSchemePathDetailService.getTransferSchemePathDefinition(faultTransferScheme);
        return ApiResponse.success(result);
    }



/**
     *
     * 开关动作顺序标签页，统计开关通过和不通过数量
     * @author luorui
     * @date 2025/5/16 19:28
     *
     **/

    @PostMapping("/countSwitchPass")
    @ApiOperation(value = "开关动作顺序标签页，统计开关通过和不通过数量")
    public ApiResponse<List<FhzgFaultTransferSchemeSwitchingSafeCheckCountDTO>> countSwitchPass(@RequestBody FaultTransferScheme faultTransferScheme) {
        List<FhzgFaultTransferSchemeSwitchingSafeCheckCountDTO>  result = faultTransferSchemeSwitchingSequenceService.countSwitchPass(faultTransferScheme);
        return ApiResponse.success(result);
    }


/**
     * 查询开关动作顺序
     * @author luorui
     * @date 2025/5/16 15:46
     *
     **/

    @PostMapping("/getTransferSchemeSwitchingSequenceBySchemeIdPage")
    @ApiOperation(value = "查询开关动作顺序")
    public ApiResponse<Page<FhzgFaultTransferSchemeSwitchingSequenceDTO>> getTransferSchemeSwitchingSequenceBySchemeIdPage(@RequestBody FaultTransferScheme faultTransferScheme) {
        Page<FhzgFaultTransferSchemeSwitchingSequenceDTO> result = faultTransferSchemeSwitchingSequenceService.getTransferSchemeSwitchingSequenceBySchemeIdPage(faultTransferScheme);
        return ApiResponse.success(result);
    }



/**
     *
     * 停电计划转供方案终态安全校验开关电流校验明细分页查询
     * @author luorui
     * @date 2025/5/16 19:28
     *
     **/

    @PostMapping("/getTransferSchemeFinalSwitchCurrentDetailByIdPage")
    @ApiOperation(value = "停电计划转供方案终态安全校验开关电流校验明细分页查询")
    public ApiResponse<Page<FhzgFaultTransferSchemeFinalSwitchCurrentDetailDTO>> getTransferSchemeFinalSwitchCurrentDetailByIdPage(@RequestBody FhzgFaultTransferSchemeFinalSwitchCurrentDetail faultTransferSchemeFinalSwitchCurrentDetail) {
        Page<FhzgFaultTransferSchemeFinalSwitchCurrentDetailDTO>  result = faultTransferSchemeFinalSwitchCurrentDetailService.getTransferSchemeFinalSwitchCurrentDetailByIdPage(faultTransferSchemeFinalSwitchCurrentDetail);
        return ApiResponse.success(result);
    }


/**
     * 停电计划转供方案终态安全校验导线电流校验明细分页查询
     * @author luorui
     * @date 2025/5/16 19:28
     *
     **/

    @PostMapping("/getTransferSchemeFinalSegmentCurrentDetailByIdPage")
    @ApiOperation(value = "停电计划转供方案终态安全校验导线电流校验明细分页查询")
    public ApiResponse<Page<FhzgFaultTransferSchemeFinalSegmentCurrentDetailDTO> > getTransferSchemeFinalSegmentCurrentDetailByIdPage(@RequestBody FhzgFaultTransferSchemeFinalSegmentCurrentDetail faultTransferSchemeFinalSegmentCurrentDetail) {
        Page<FhzgFaultTransferSchemeFinalSegmentCurrentDetailDTO>  result = faultTransferSchemeFinalSegmentCurrentDetailService.getTransferSchemeFinalSegmentCurrentDetailByIdPage(faultTransferSchemeFinalSegmentCurrentDetail);
        return ApiResponse.success(result);
    }


/**
     * 可靠性校验对侧线路负载率分页查询
     *
     * @author luorui
     * @date 2025/5/16 19:28
     **/

    @PostMapping("/getTransferSchemeOppositeLineLoadFactorByIdPage")
    @ApiOperation(value = "可靠性校验对侧线路负载率分页查询")
    public ApiResponse<Page<FhzgFaultTransferSchemeOppositeLineLoadFactorDTO>> getTransferSchemeOppositeLineLoadFactorByIdPage(@RequestBody FaultTransferSchemeOppositeLineLoadFactor faultTransferSchemeOppositeLineLoadFactor) {
        Page<FhzgFaultTransferSchemeOppositeLineLoadFactorDTO> result = fhzgPlanTransferSchemeOppositeLineLoadFactorService.getTransferSchemeOppositeLineLoadFactorByIdPage(faultTransferSchemeOppositeLineLoadFactor);
        return ApiResponse.success(result);
    }


    /**
     * 可靠性校验，损失用户信息查询
     *
     * @author luorui
     * @date 2025/5/16 19:28
     **/
    @PostMapping("/getFhzgFaultTransferSchemeUsersByIdPage")
    @ApiOperation(value = "可靠性校验，损失用户信息查询")
    public ApiResponse<UsersPage<FhzgFaultTransferSchemeUsersDTO>> getFhzgPlanTransferSchemeUsersByIdPage(@RequestBody FhzgFaultTransferSchemeUsersReqDTO faultTransferSchemeUsersReqDTO) {
        UsersPage<FhzgFaultTransferSchemeUsersDTO> result = faultTransferSchemeUsersService.getFhzgFaultTransferSchemeUsersByIdPage(faultTransferSchemeUsersReqDTO);
        return ApiResponse.success(result);
    }

    /**
     *
     *  统计方案下，损失用户数据，聚合到对应的负荷开关下
     * @author luorui
     * @date 2025/5/16 19:28
     *
     **/
    @PostMapping("/countLoadSwitchLoseUsersByScheme")
    @ApiOperation(value = " 统计方案下，损失用户数据，聚合到对应的负荷开关下")
    public ApiResponse<List<LoadSwitchLoseUsersDTO> > countLoadSwitchLoseUsersByScheme(@RequestBody FhzgPlanTransferSchemeUsersReqDTO fhzgPlanTransferSchemeUsersReqDTO) {
        List<LoadSwitchLoseUsersDTO> result = faultTransferSchemeUsersService.countLoadSwitchLoseUsersByScheme(fhzgPlanTransferSchemeUsersReqDTO.getSchemeId());
        return ApiResponse.success(result);
    }

    /**
     * 获取方案下所有开关的p,i值
     */
    @PostMapping("/getAllSwitchBySchemeId")
    @ApiOperation(value = " 获取方案下所有开关的p,i值")
    public ApiResponse<List<AllSwitchInfoListDTO>> getAllSwitchBySchemeId(@RequestBody FhzgPlanTransferSchemeAllSwitchDTO fhzgPlanTransferSchemeAllSwitchDTO) {
        List<AllSwitchInfoListDTO> result = faultTransferSchemeService.getAllSwitchBySchemeId(fhzgPlanTransferSchemeAllSwitchDTO.getSchemeId());
        return ApiResponse.success(result);
    }
}
