package com.hdkj.lt.bf.controller;

import cn.hutool.core.bean.BeanUtil;
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.FhzgPowerTransferInfoVO;
import com.hdkj.lt.bf.entity.vo.SectionTransferPage;
import com.hdkj.lt.bf.service.*;
import com.hdkj.lt.core.bizms.modle.dto.FhzgPlanTransferSchemeAllSwitchDTO;
import com.hdkj.lt.core.bizms.modle.dto.FhzgPlanTransferSchemePathDetailDTO;
import com.hdkj.lt.core.bizms.modle.dto.FhzgPlanTransferSchemeUsersReqDTO;
import com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferScheme;
import com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferSchemeFinalSegmentCurrentDetail;
import com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferSchemeFinalSwitchCurrentDetail;
import com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferSchemeOppositeLineLoadFactor;
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("/fhzgPlanTransferScheme")
@RequiredArgsConstructor
public class FhzgPlanTransferSchemeController {

    @Autowired
    FhzgPlanTransferSchemeService fhzgPlanTransferSchemeService;

    @Autowired
    FhzgPlanTransferSchemeLoopCloseCheckService fhzgPlanTransferSchemeLoopCloseCheckService;

    @Autowired
    FhzgPlanTransferSchemePathDetailService fhzgPlanTransferSchemePathDetailService;

    @Autowired
    FhzgPlanTransferSchemeSwitchingSequenceService fhzgPlanTransferSchemeSwitchingSequenceService;

    @Autowired
    FhzgPlanTransferSchemeFinalSwitchCurrentDetailService fhzgPlanTransferSchemeFinalSwitchCurrentDetailService;

    @Autowired
    FhzgPlanTransferSchemeFinalSegmentCurrentDetailService fhzgPlanTransferSchemeFinalSegmentCurrentDetailService;

    @Autowired
    FhzgPlanTransferSchemeOppositeLineLoadFactorService fhzgPlanTransferSchemeOppositeLineLoadFactorService;

    @Autowired
    FhzgPlanTransferSchemeUsersService fhzgPlanTransferSchemeUsersService;

    @Autowired
    FhzgPlanTransferSchemePowerTransferInfoService fhzgPlanTransferSchemePowerTransferInfoService;



    /**
     * 停电计划转供方案列表查询接口
     * @param fhzgPlanTransferSchemeListReqDTO
     * @return
     */
    @PostMapping("/getTransferSchemeListByPlanId")
    @ApiOperation(value = "停电计划转供方案列表查询接口")
    public ApiResponse<List<FhzgPlanTransferSchemeDTO> > getTransferSchemeListByPlanId(@RequestBody FhzgPlanTransferSchemeListReqDTO fhzgPlanTransferSchemeListReqDTO) {
        FhzgPlanTransferScheme fhzgPlanTransferScheme = new FhzgPlanTransferScheme();
        BeanUtil.copyProperties(fhzgPlanTransferSchemeListReqDTO,fhzgPlanTransferScheme);
        List<FhzgPlanTransferSchemeDTO> result= fhzgPlanTransferSchemeService.getTransferSchemeListByPlanId(fhzgPlanTransferScheme);
        return ApiResponse.success(result);
    }


    /**
     * 查询停电计划下的推荐方案和不通过方案数量
     * @param fhzgPlanTransferSchemeListReqDTO
     * @return
     */
    @PostMapping("/getTransferSchemeCheckResultCountByPlanId")
    @ApiOperation(value = "推荐方案和不通过方案数量查询接口")
    public ApiResponse<List<FhzgPlanTransferSchemeCheckCountResultDTO>> getTransferSchemeCheckResultCountByPlanId(@RequestBody FhzgPlanTransferSchemeListReqDTO fhzgPlanTransferSchemeListReqDTO) {
        FhzgPlanTransferScheme fhzgPlanTransferScheme = new FhzgPlanTransferScheme();
        BeanUtil.copyProperties(fhzgPlanTransferSchemeListReqDTO,fhzgPlanTransferScheme);
        List<FhzgPlanTransferSchemeCheckCountResultDTO> result = fhzgPlanTransferSchemeService.getTransferSchemeCheckResultCountByPlanId(fhzgPlanTransferScheme);
        return ApiResponse.success(result);
    }


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

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


    /**
     * 停电计划转供方案转供路径概述查询
     * @param fhzgPlanTransferScheme
     * @return
     */
    @PostMapping("/getTransferSchemePathDefinition")
    @ApiOperation(value = "查询转供路径概述")
    public ApiResponse<FhzgPlanTransferSchemePathDefinitionDTO> getTransferSchemePathDefinition(@RequestBody FhzgPlanTransferScheme fhzgPlanTransferScheme) {
        FhzgPlanTransferSchemePathDefinitionDTO result = fhzgPlanTransferSchemePathDetailService.getTransferSchemePathDefinition(fhzgPlanTransferScheme);
        return ApiResponse.success(result);
    }


    /**
     *
     * 开关动作顺序标签页，统计开关通过和不通过数量
     * @author luorui
     * @date 2025/5/16 19:28
     *
     **/
    @PostMapping("/countSwitchPass")
    @ApiOperation(value = "开关动作顺序标签页，统计开关通过和不通过数量")
    public ApiResponse<List<FhzgPlanTransferSchemeSwitchingSafeCheckCountDTO>> countSwitchPass(@RequestBody FhzgPlanTransferScheme fhzgPlanTransferScheme) {
        List<FhzgPlanTransferSchemeSwitchingSafeCheckCountDTO>  result = fhzgPlanTransferSchemeSwitchingSequenceService.countSwitchPass(fhzgPlanTransferScheme);
        return ApiResponse.success(result);
    }

    /**
     * 查询开关动作顺序
     * @author luorui
     * @date 2025/5/16 15:46
     *
     **/
    @PostMapping("/getTransferSchemeSwitchingSequenceBySchemeIdPage")
    @ApiOperation(value = "查询开关动作顺序")
    public ApiResponse<Page<FhzgPlanTransferSchemeSwitchingSequenceDTO>> getTransferSchemeSwitchingSequenceBySchemeIdPage(@RequestBody FhzgPlanTransferScheme fhzgPlanTransferScheme) {
        Page<FhzgPlanTransferSchemeSwitchingSequenceDTO> result = fhzgPlanTransferSchemeSwitchingSequenceService.getTransferSchemeSwitchingSequenceBySchemeIdPage(fhzgPlanTransferScheme);
        return ApiResponse.success(result);
    }


    /**
     *
     * 停电计划转供方案终态安全校验开关电流校验明细分页查询
     * @author luorui
     * @date 2025/5/16 19:28
     *
     **/
    @PostMapping("/getTransferSchemeFinalSwitchCurrentDetailByIdPage")
    @ApiOperation(value = "停电计划转供方案终态安全校验开关电流校验明细分页查询")
    public ApiResponse<Page<FhzgPlanTransferSchemeFinalSwitchCurrentDetailDTO> > getTransferSchemeFinalSwitchCurrentDetailByIdPage(@RequestBody FhzgPlanTransferSchemeFinalSwitchCurrentDetail fhzgPlanTransferSchemeFinalSwitchCurrentDetail) {
        Page<FhzgPlanTransferSchemeFinalSwitchCurrentDetailDTO>  result = fhzgPlanTransferSchemeFinalSwitchCurrentDetailService.getTransferSchemeFinalSwitchCurrentDetailByIdPage(fhzgPlanTransferSchemeFinalSwitchCurrentDetail);
        return ApiResponse.success(result);
    }

    /**
     * 停电计划转供方案终态安全校验导线电流校验明细分页查询
     * @author luorui
     * @date 2025/5/16 19:28
     *
     **/
    @PostMapping("/getTransferSchemeFinalSegmentCurrentDetailByIdPage")
    @ApiOperation(value = "停电计划转供方案终态安全校验导线电流校验明细分页查询")
    public ApiResponse<Page<FhzgPlanTransferSchemeFinalSegmentCurrentDetailDTO> > getTransferSchemeFinalSegmentCurrentDetailByIdPage(@RequestBody FhzgPlanTransferSchemeFinalSegmentCurrentDetail fhzgPlanTransferSchemeFinalSegmentCurrentDetail) {
        Page<FhzgPlanTransferSchemeFinalSegmentCurrentDetailDTO>  result = fhzgPlanTransferSchemeFinalSegmentCurrentDetailService.getTransferSchemeFinalSegmentCurrentDetailByIdPage(fhzgPlanTransferSchemeFinalSegmentCurrentDetail);
        return ApiResponse.success(result);
    }

    /**
     * 可靠性校验对侧线路负载率查询
     * @author luorui
     * @date 2025/5/16 19:28
     *
     **/
    @PostMapping("/getTransferSchemeOppositeLineLoadFactorByIdPage")
    @ApiOperation(value = "可靠性校验对侧线路负载率查询")
    public ApiResponse<List<FhzgPlanTransferSchemeOppositeLineLoadFactorDTO>> getTransferSchemeOppositeLineLoadFactorByIdPage(@RequestBody FhzgPlanTransferSchemeOppositeLineLoadFactor fhzgPlanTransferSchemeOppositeLineLoadFactor) {
        List<FhzgPlanTransferSchemeOppositeLineLoadFactorDTO>  result = fhzgPlanTransferSchemeOppositeLineLoadFactorService.getTransferSchemeOppositeLineLoadFactorByIdPage(fhzgPlanTransferSchemeOppositeLineLoadFactor);
        return ApiResponse.success(result);
    }

    /**
     * 可靠性校验主变负载率查询
     * @author luorui
     * @date 2025/5/16 19:28
     *
     **/
    @PostMapping("/getPowerTransferInfo")
    @ApiOperation(value = "主变负载率查询")
    public ApiResponse<List<FhzgPowerTransferInfoVO>> getPowerTransferInfo(@RequestBody FhzgPlanTransferSchemeOppositeLineLoadFactor fhzgPlanTransferSchemeOppositeLineLoadFactor) {
        List<FhzgPowerTransferInfoVO>  result = fhzgPlanTransferSchemePowerTransferInfoService.getPowerTransferInfo(fhzgPlanTransferSchemeOppositeLineLoadFactor);
        return ApiResponse.success(result);
    }


    /**
     *
     * 可靠性校验，损失用户信息查询
     * @author luorui
     * @date 2025/5/16 19:28
     *
     **/
    @PostMapping("/getFhzgPlanTransferSchemeUsersByIdPage")
    @ApiOperation(value = "可靠性校验，损失用户信息查询")
    public ApiResponse<UsersPage<FhzgPlanTransferSchemeUsersDTO> > getFhzgPlanTransferSchemeUsersByIdPage(@RequestBody FhzgPlanTransferSchemeUsersReqDTO fhzgPlanTransferSchemeUsersReqDTO) {
        UsersPage<FhzgPlanTransferSchemeUsersDTO>  result = fhzgPlanTransferSchemeUsersService.getFhzgPlanTransferSchemeUsersByIdPage(fhzgPlanTransferSchemeUsersReqDTO);
        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 = fhzgPlanTransferSchemeUsersService.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 = fhzgPlanTransferSchemeService.getAllSwitchBySchemeId(fhzgPlanTransferSchemeAllSwitchDTO.getSchemeId());
        return ApiResponse.success(result);
    }
}
