package com.njcn.device.pms.controller.ledgerManger;

import cn.hutool.core.collection.CollectionUtil;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.dto.SimpleDTO;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pms.pojo.dto.PmsGeneralDeviceDTO;
import com.njcn.device.pms.pojo.param.PmsDeviceInfoParam;
import com.njcn.device.pms.pojo.param.PwPmsMonitorParam;
import com.njcn.device.pms.service.majornetwork.IPmsGeneralDeviceService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2022年10月14日 09:19
 */
@Slf4j
@Api(tags = "获取终端信息")
@RestController
@RequestMapping("/pmsDeviceInfo")
@RequiredArgsConstructor
public class PmsGeneralDeviceController extends BaseController {

    private final IPmsGeneralDeviceService generalPmsDeviceService;


    /**
     * 获取指定组织下台账综合信息
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getPmsDeviceInfoWithInOrg")
    @ApiOperation("获取指定组织下台账综合信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pmsDeviceInfoParam", value = "查询台账条件", required = true)
    })
    public HttpResult<List<PmsGeneralDeviceDTO>> getPmsDeviceInfoWithInOrg(@RequestBody @Validated PmsDeviceInfoParam pmsDeviceInfoParam) {
        String methodDescribe = getMethodDescribe("getPmsDeviceInfoWithInOrg");
        List<PmsGeneralDeviceDTO> deptDeviceInfos = generalPmsDeviceService.getPmsDeviceInfoWithInOrg(pmsDeviceInfoParam);
        if (CollectionUtil.isEmpty(deptDeviceInfos)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, deptDeviceInfos, methodDescribe);
        }
    }

    /**
     * 主网获取指定组织下变电站
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getPmsPowerrInfoWithInOrg")
    @ApiOperation("主网获取指定组织下变电站")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pmsDeviceInfoParam", value = "查询变电站条件", required = true)
    })
    public HttpResult<List<SimpleDTO>> getPmsPowerrInfoWithInOrg(@RequestBody @Validated PmsDeviceInfoParam pmsDeviceInfoParam) {
        String methodDescribe = getMethodDescribe("getPmsPowerrInfoWithInOrg");
        List<SimpleDTO> pmsPowerrInfoList = generalPmsDeviceService.getPmsPowerrInfoWithInOrg(pmsDeviceInfoParam);
        if (CollectionUtil.isEmpty(pmsPowerrInfoList)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pmsPowerrInfoList, methodDescribe);
        }
    }


    /**
     * 获取指定组织下台账综合信息
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getPwPmsDeviceInfoWithOrgId")
    @ApiOperation("获取指定组织下配网信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pmsDeviceInfoParam", value = "查询台账条件", required = true)
    })
    public HttpResult<List<PmsGeneralDeviceDTO>> getPwPmsDeviceInfoWithOrgId(@RequestBody @Validated PmsDeviceInfoParam pmsDeviceInfoParam) {
        String methodDescribe = getMethodDescribe("getPmsDeviceInfoByOrgId");
        List<PmsGeneralDeviceDTO> deptDeviceInfos = generalPmsDeviceService.getPmsDeviceInfoByOrgId(pmsDeviceInfoParam);
        if (CollectionUtil.isEmpty(deptDeviceInfos)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, deptDeviceInfos, methodDescribe);
        }
    }


    /**
     * 根据单位获取单位的配网监测点集合
     * @author cdf
     * @date 2023/9/4
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getPwPmsMonitorIds")
    @ApiOperation("获取指定单位下配网监测点")
    @ApiImplicitParam(name = "deptId", value = "查询台账条件", required = true)
    @ApiIgnore
    public HttpResult<List<String>> getPwPmsMonitorIds(@RequestBody PwPmsMonitorParam pwPmsMonitorParam) {
        String methodDescribe = getMethodDescribe("getPwPmsMonitorIds");
        List<String> deptDeviceInfos = generalPmsDeviceService.getPwPmsMonitorIds(pwPmsMonitorParam.getOrgId(),pwPmsMonitorParam.getMonitorSort());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, deptDeviceInfos, methodDescribe);
    }







}
