package com.hdkj.lt.bf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdkj.lt.bf.aspect.RequiresCountryPermissions;
import com.hdkj.lt.bf.entity.FhzgPlanPowerCut;
import com.hdkj.lt.bf.entity.dto.CreatePlanPowerCutDTO;
import com.hdkj.lt.bf.entity.dto.HasDataTagDTO;
import com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanAwaitTransferSwitchSection;
import com.hdkj.lt.bf.entity.FhzgDistCustomer;
import com.hdkj.lt.bf.entity.dto.FhzgDistCustomerCountDTO;
import com.hdkj.lt.core.bizms.modle.vo.FhzgAwaitTransferUsersVO;
import com.hdkj.lt.bf.entity.vo.FhzgOppositeLineCarryCapacityVO;
import com.hdkj.lt.bf.entity.vo.FhzgPlanPowerCutVO;
import com.hdkj.lt.core.bizms.modle.dto.FhzgDistCustomerDTO;
import com.hdkj.lt.bf.service.*;
import com.hdkj.lt.core.mvc.BaseController;
import com.hdkj.hussar.ApiResponse;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 计划停电转供
 *
 * @author zhousc
 * @since 2025-05-07
 */
@RestController
@RequestMapping("/fhzgPlanPowerCut")
@RequiredArgsConstructor
public class FhzgPlanPowerCutController extends BaseController {

    private final FhzgPlanPowerCutService planPowerCutService;

    private final FhzgDistCustomerService distCustomerService;

    private final FhzgPlanAwaitTransferSwitchSectionService awaitTransferSwitchSectionServices;

    private final FhzgPlanAwaitTransferUsersService awaitTransferUsersService;

    private final FhzgPlanOppositeLineCarryCapacityService oppositeLineCarryCapacityService;

    /**
     * 获取计划停电方案列表
     *
     * @param planPowerCut
     * @return
     */
    @PostMapping("/getSchemeList")
    @ApiOperation(value = "获取计划停电方案列表")
    public ApiResponse<Page<FhzgPlanPowerCutVO>> getSchemeList(@RequestBody FhzgPlanPowerCut planPowerCut) {
        return ApiResponse.success(planPowerCutService.getSchemeList(planPowerCut));
    }

    /**
     * 获取停电区域光伏列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/getDistCustomerList")
    @ApiOperation(value = "获取停电区域光伏列表")
    public ApiResponse<Page<FhzgDistCustomer>> getDistCustomerList(@RequestBody FhzgDistCustomerDTO dto) {
        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getPlanId() == null) {
            return fail("计划停电ID不能为空");
        }
        return ApiResponse.success(distCustomerService.getCustomerList(dto));
    }

    /**
     * 统计停电区域光伏用户数量
     *
     * @param dto
     * @return
     */
    @PostMapping("/getDistCustomerCount")
    @ApiOperation(value = "统计停电区域光伏用户数量")
    public ApiResponse<FhzgDistCustomerCountDTO> getDistCustomerCount(@RequestBody FhzgDistCustomerDTO dto) {
        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getPlanId() == null) {
            return fail("计划停电ID不能为空");
        }
        return ApiResponse.success(distCustomerService.getDistCustomerCount(dto));
    }

    /**
     * 获取待转供开关段列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/getAwaitTransferSwitchSectionList")
    @ApiOperation(value = "获取待转供开关段列表")
    public ApiResponse<Page<FhzgPlanAwaitTransferSwitchSection>> getAwaitTransferSwitchSectionList(@RequestBody FhzgDistCustomerDTO dto) {
        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getPlanId() == null) {
            return fail("计划停电ID不能为空");
        }
        return ApiResponse.success(awaitTransferSwitchSectionServices.getSwitchSectionList(dto));
    }

    /**
     * 获取待转供用户列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/getAwaitTransferUsersList")
    @ApiOperation(value = "获取待转供用户列表")
    public ApiResponse<Page<FhzgAwaitTransferUsersVO>> getAwaitTransferUsersList(@RequestBody FhzgDistCustomerDTO dto) {
        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getPlanId() == null) {
            return fail("计划停电ID不能为空");
        }
        return ApiResponse.success(awaitTransferUsersService.getUserList(dto));
    }

    /**
     * 获取对侧联络线路承载力分析列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/getOppositeLineCarryCapacityList")
    @ApiOperation(value = "获取对侧联络线路承载力分析列表")
    public ApiResponse<Page<FhzgOppositeLineCarryCapacityVO>> getOppositeLineCarryCapacityList(@RequestBody FhzgDistCustomerDTO dto) {
        if (dto == null) {
            return fail("参数不能为空");
        }
        if (dto.getPlanId() == null) {
            return fail("计划停电ID不能为空");
        }
        return ApiResponse.success(oppositeLineCarryCapacityService.getOppositeLineCarryCapacityList(dto));
    }

    /**
     *
     * 查询计划下，转供范围，转供计划，转供评分是否有数据，返回给前端禁用按钮
     * @author luorui
     * @date 2025/5/27 10:36
     *
     **/
    @PostMapping("/getHasDataTag")
    @ApiOperation(value = "查询计划下，转供范围，转供计划，转供评分是否有数据，返回给前端禁用按钮")
    public ApiResponse<HasDataTagDTO> getHasDataTag(@RequestBody FhzgDistCustomerDTO dto) {
        if (dto.getPlanId() == null) {
            return fail("计划停电ID不能为空");
        }
        HasDataTagDTO hasDataTagDTO = planPowerCutService.getHasDataTag( dto);
        return ApiResponse.success(hasDataTagDTO);
    }
    /**
     * 根据planId或者planNo查询计划详情，优先根据planId查询
     * @author luorui
     * @date 2025/6/28 15:27
     *
     **/
    @PostMapping("/getByPlanIdOrPlanNo")
    @ApiOperation(value = "根据planId或者planNo查询计划详情，优先根据planId查询")
    public ApiResponse<FhzgPlanPowerCut> getByPlanIdOrPlanNo(@RequestBody FhzgDistCustomerDTO dto) {
        FhzgPlanPowerCut result =  planPowerCutService.getByPlanIdOrPlanNo(dto);
        return ApiResponse.success(result);
    }

    @PostMapping("/createPlanPowerCut")
    @ApiOperation(value = "创建计划停电数据")
    public ApiResponse<Boolean> createPlanPowerCut(@RequestBody CreatePlanPowerCutDTO createPlanPowerCutDTO) {
        return planPowerCutService.createPlanPowerCut(createPlanPowerCutDTO);
    }

}
