package com.njcn.harmonic.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
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.common.utils.LogUtil;
import com.njcn.device.pq.pojo.dto.PollutionLineDTO;
import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO;
import com.njcn.harmonic.pojo.param.HarmonicPublicParam;
import com.njcn.harmonic.pojo.param.PollutionSubstationQuryParam;
import com.njcn.harmonic.pojo.vo.PollutionSubstationVO;
import com.njcn.harmonic.pojo.vo.PollutionVO;
import com.njcn.harmonic.service.PollutionSubstationService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
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;

/**
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2022/10/13  9:39【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/PollutionSubstation")
@Api(tags = "变电站污染统计")
@AllArgsConstructor
public class PollutionSubstationController extends BaseController {

    private final PollutionSubstationService pollutionSubstationService;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getPollutionSubstationData")
    @ApiOperation("按变电站及指标类型展示污染")
    @ApiImplicitParam(name = "pollutionSubstationQuryParam", value = "污染指标查询参数", required = true)
    public HttpResult<List<PollutionSubstationVO>> getPollutionSubstationData(@RequestBody @Validated PollutionSubstationQuryParam pollutionSubstationQuryParam) {
        String methodDescribe = getMethodDescribe ("getPollutionSubstationData");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, pollutionSubstationQuryParam);
        List<PollutionSubstationVO> list = pollutionSubstationService.getPollutionSubstationData (pollutionSubstationQuryParam);
        return HttpResultUtil.assembleCommonResponseResult (CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deptSubstationRelations")
    @ApiOperation("污区图-部门变电站关系")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<List<PollutionVO>> deptSubstationRelations(@RequestBody HarmonicPublicParam param) {
        String methodDescribe = getMethodDescribe("deptSubstationRelations");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        List<PollutionVO> list = pollutionSubstationService.getDeptSubstationRelations(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getSubstationInfoById")
    @ApiOperation("污区图-根据部门获取变电站详情")
    @ApiImplicitParam(name = "param", value = "部门参数", required = true)
    public HttpResult<List<PollutionSubstationDTO>> getSubstationInfoById(@RequestBody HarmonicPublicParam param) {
        String methodDescribe = getMethodDescribe("getSubstationInfoById");
        LogUtil.njcnDebug(log, "{}，部门参数：{}", methodDescribe, param);
        List<PollutionSubstationDTO> list = pollutionSubstationService.getSubstationInfoById(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineInfoById")
    @ApiOperation("污区图-根据变电站获取监测点详情")
    @ApiImplicitParam(name = "param", value = "变电站参数", required = true)
    public HttpResult<List<PollutionLineDTO>> getLineInfoById(@RequestBody HarmonicPublicParam param) {
        String methodDescribe = getMethodDescribe("getLineInfoById");
        LogUtil.njcnDebug(log, "{}，变电站参数：{}", methodDescribe, param);
        List<PollutionLineDTO> list = pollutionSubstationService.getLineInfoById(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineRank")
    @ApiOperation("污区图-获取前十监测点排名")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<List<PollutionLineDTO>> getLineRank(@RequestBody HarmonicPublicParam param) {
        String methodDescribe = getMethodDescribe("getLineRank");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        List<PollutionLineDTO> list = pollutionSubstationService.getLineRankTop10(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
}
