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

import cn.hutool.core.date.TimeInterval;
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.biz.pojo.dto.*;
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
import com.njcn.device.pms.service.ledgerManger.CommTerminalService;
import com.njcn.device.pms.service.majornetwork.IMonitorService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
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 wr
 * @description
 * @date 2023/4/26 10:00
 */
@RestController
@RequestMapping("/commTerminal")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "通用台账-所有子孙部门以及监测点")
public class CommTerminalController extends BaseController {

    private final IMonitorService monitorService;


    private final CommTerminalService commTerminalService;

    /**
     * 通过部门获取所有子集部门所拥有的监测点
     *
     * @author wr
     * @date 2023/4/26
     */
    @PostMapping("/deptGetLineIds")
    @ApiOperation("通过部门获取所有子集部门所拥有的监测点")
    @ApiImplicitParam(name = "param", value = "请求参数", required = true)
    public HttpResult<List<DeptGetChildrenDTO>> deptGetLineList(@RequestBody @Validated DeptGetLineParam param) {
        String methodDescribe = getMethodDescribe("deptGetLineList");
        List<DeptGetChildrenDTO> monitor = monitorService.deptMonitor(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, monitor, methodDescribe);
    }





    /**
     * 根据单位获取所有子单位信息
     * @author cdf
     * @date 2023/5/10
     */
    @PostMapping("getDeptChildrenByParent")
    @ApiOperation("根据单位获取所有子单位信息")
    @ApiImplicitParam(name = "deptGetLineParam", value = "请求体", required = true)
    public HttpResult<List<DeptGetBase>> getDeptChildrenByParent(@RequestBody @Validated DeptGetLineParam deptGetLineParam) {
        TimeInterval timer = new TimeInterval();
        String methodDescribe = getMethodDescribe("getDeptChildrenByParent");
        List<DeptGetBase> result = commTerminalService.getDeptChildrenByParent(deptGetLineParam);
        log.info("运行时长" + timer.intervalRestart());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    /**
     * 根据单位获取监测点信息
     * @author cdf
     * @date 2023/5/10
     */
    @PostMapping("deptGetLine")
    @ApiOperation("根据单位获取监测点信息")
    @ApiImplicitParam(name = "deptGetLineParam", value = "请求体", required = true)
    public HttpResult<List<DeptGetChildrenMoreDTO>> deptGetLine(@RequestBody @Validated DeptGetLineParam deptGetLineParam) {
        TimeInterval timer = new TimeInterval();
        String methodDescribe = getMethodDescribe("deptGetLine");
        List<DeptGetChildrenMoreDTO> result = commTerminalService.deptGetLine(deptGetLineParam);
        log.info("运行时长" + timer.intervalRestart());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }




    /**
     * 根据单位获取所有变电站
     * @author cdf
     * @date 2023/5/10
     */
    @PostMapping("deptGetSubStation")
    @ApiOperation("根据单位获取所有变电站")
    @ApiImplicitParam(name = "deptGetLineParam", value = "请求体", required = true)
    public HttpResult<List<DeptGetSubStationDTO>> deptSubStation(@RequestBody @Validated DeptGetLineParam deptGetLineParam) {
        TimeInterval timer = new TimeInterval();
        String methodDescribe = getMethodDescribe("deptSubStation");
        List<DeptGetSubStationDTO> result = commTerminalService.deptSubStation(deptGetLineParam);
        log.info("运行时长" + timer.intervalRestart());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    /**
     * 根据单位获取所有变电站
     * @author cdf
     * @date 2023/5/10
     */
    @PostMapping("deptGetBusBar")
    @ApiOperation("根据单位获取所有母线")
    @ApiImplicitParam(name = "deptGetLineParam", value = "请求体", required = true)
    public HttpResult<List<DeptGetBusBarDTO>> deptBusBar(@RequestBody @Validated DeptGetLineParam deptGetLineParam) {
        TimeInterval timer = new TimeInterval();
        String methodDescribe = getMethodDescribe("deptBusBar");
        List<DeptGetBusBarDTO> result = commTerminalService.deptBusBar(deptGetLineParam);
        log.info("运行时长" + timer.intervalRestart());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }



    /**
     * 根据单位获取所有装置
     * @author cdf
     * @date 2023/5/10
     */
    @PostMapping("deptGetDevice")
    @ApiOperation("根据单位获取所有装置")
    @ApiImplicitParam(name = "deptGetLineParam", value = "请求体", required = true)
    public HttpResult<List<DeptGetDeviceDTO>> deptGetDevice(@RequestBody @Validated DeptGetLineParam deptGetLineParam) {
        TimeInterval timer = new TimeInterval();
        String methodDescribe = getMethodDescribe("deptGetDevice");
        List<DeptGetDeviceDTO> result = commTerminalService.deptGetDevice(deptGetLineParam,0);
        log.info("运行时长" + timer.intervalRestart());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    /**
     * 根据单位获取单位下的装置以及装置下的监测点
     * @author cdf
     * @date 2023/5/10
     */
    @PostMapping("deptGetDeviceAndMonitor")
    @ApiOperation("根据单位获取装置以及监测点")
    @ApiImplicitParam(name = "deptGetLineParam", value = "请求体", required = true)
    public HttpResult<List<DeptGetDeviceDTO>> deptGetDeviceAndMonitor(@RequestBody @Validated DeptGetLineParam deptGetLineParam) {
        TimeInterval timer = new TimeInterval();
        String methodDescribe = getMethodDescribe("deptGetDeviceAndMonitor");
        List<DeptGetDeviceDTO> result = commTerminalService.deptGetDevice(deptGetLineParam,1);
        log.info("运行时长" + timer.intervalRestart());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    /**
     * 根据单站id获取监测点信息
     * @author cdf
     * @date 2023/5/10
     */
    @PostMapping("substationGetLine")
    @ApiOperation("根据电站获取所有监测点")
    @ApiImplicitParam(name = "substationId", value = "请求体", required = true)
    public HttpResult<LineDevGetBandDTO> substationGetLine(@RequestParam("substationId")String substationId) {
        TimeInterval timer = new TimeInterval();
        String methodDescribe = getMethodDescribe("substationGetLine");
        LineDevGetBandDTO result = commTerminalService.substationGetLine(substationId);
        log.info("运行时长" + timer.intervalRestart());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    /**
     * 根据母线id获取监测点信息
     * @author cdf
     * @date 2023/5/10
     */
    @PostMapping("busBarGetLine")
    @ApiOperation("根据母线id获取监测点信息")
    @ApiImplicitParam(name = "busBarId", value = "请求体", required = true)
    public HttpResult<LineDevGetBandDTO> busBarGetLine(@RequestParam("busBarId")String busBarId) {
        TimeInterval timer = new TimeInterval();
        String methodDescribe = getMethodDescribe("busBarGetLine");
        LineDevGetBandDTO result = commTerminalService.busBarGetLine(busBarId);
        log.info("运行时长" + timer.intervalRestart());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    /**
     * 重新计算限值
     *
     * @author cdf
     * @date 2022/5/17
     */
    @ApiOperation("监测点-重新计算限值")
    @GetMapping(value = "updatePmsOverLimit")
    public HttpResult<String> updatePmsOverLimit() {
        String methodDescribe = getMethodDescribe("updatePmsOverLimit");
        String count = commTerminalService.updatePmsOverLimit();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, count, methodDescribe);
    }

    /**
     * 用于返回pq 还是pms系统
     * @author cdf
     * @date 2023/8/3
     */
    @GetMapping("isPqOrPms")
    @ApiOperation("用于返回pq 还是pms系统")
    @ApiIgnore
    public HttpResult<String> isPqOrPms() {
        String methodDescribe = getMethodDescribe("isPqOrPms");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "pms", methodDescribe);
    }
}
