package com.njcn.csdevice.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.csdevice.pojo.vo.LineOverLimitVO;
import com.njcn.csdevice.service.IOverLimitService;
import com.njcn.device.biz.pojo.po.Overlimit;
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.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;


@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "监测点限值信息查询")
public class PQOverlimitController extends BaseController {

    private final IOverLimitService overLimitService;

    // --------  3个重复的代码！！！！ ----------
    /**
     * 来源于CommTerminalController的getOverLimitData
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/commTerminal/getOverLimitData")
    @ApiOperation("根据监测点id获取越限数值")
    @ApiImplicitParam(name = "id", value = "监测点id", required = true)
    public HttpResult<Overlimit> getOverLimitDataTerminal(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getOverLimitData");
        Overlimit result = overLimitService.getOverLimitDataById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/line/getOverLimitData")
    @ApiOperation("根据监测点id获取越限数值")
    @ApiImplicitParam(name = "id", value = "监测点id", required = true)
    public HttpResult<Overlimit> getOverLimitData(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getOverLimitData");
        Overlimit result = overLimitService.getOverLimitDataById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/line/getLineOverLimitData")
    @ApiOperation("根据监测点id获取越限详情")
    @ApiImplicitParam(name = "id", value = "监测点id", required = true)
    public HttpResult<LineOverLimitVO> getLineOverLimitData(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getLineOverLimitData");
        LineOverLimitVO result = overLimitService.getLineOverLimitDataById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/overLimit/getOverLimitByLineIds")
    @ApiOperation("监测点集合获取限值")
    @ApiImplicitParam(name = "lineIds", value = "监测点ids", required = true)
    @ApiIgnore
    public HttpResult<List<Overlimit>> getOverLimitByLineIds(@RequestBody List<String> lineIds){
        String methodDescribe = getMethodDescribe("getOverLimitByLineIds");
        List<Overlimit> overLimitList= overLimitService.list(new LambdaQueryWrapper<Overlimit>().in(Overlimit::getId,lineIds));
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, overLimitList, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/commTerminal/getOverLimitDataByIds")
    @ApiOperation("根据监测点id集合获取越限数值")
    @ApiImplicitParam(name = "ids", value = "监测点id集合", required = true)
    public HttpResult<List<Overlimit>> getOverLimitDataByIds(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("getOverLimitDataByIds");
        List<Overlimit> result = overLimitService.listByIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/overLimit/getLimitMapsByLineIds")
    @ApiOperation("监测点集合获取限值")
    @ApiImplicitParam(name = "lineIds", value = "监测点ids", required = true)
    @ApiIgnore
    public HttpResult<List<Map<String, Object>>> getLimitMapsByLineIds(@RequestBody List<String> lineIds){
        String methodDescribe = getMethodDescribe("getLimitMapsByLineIds");
        List<Map<String, Object>> overLimitList= overLimitService.listMaps(new LambdaQueryWrapper<Overlimit>().in(Overlimit::getId,lineIds));
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, overLimitList, methodDescribe);
    }
}
