package com.njcn.device.pq.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.device.pq.pojo.param.RunManageParam;
import com.njcn.device.pq.pojo.vo.RunManageVO;
import com.njcn.device.pq.pojo.vo.RunTimeVO;
import com.njcn.device.pq.pojo.vo.TerminalLedgerVO;
import com.njcn.device.pq.service.RunManageService;
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.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;

/**
 * 运行管理
 *
 * @author denghuajun
 * @version 1.0.0
 * @date 2022/3/30
 */
@Slf4j
@Api(tags = "运行管理")
@RestController
@RequestMapping("/runManage")
@RequiredArgsConstructor
public class RunManageController extends BaseController {

    private final RunManageService runManageService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineLedger")
    @ApiOperation("监测点台账信息")
    @ApiImplicitParam(name = "runManageParam", value = "监测点台账参数", required = true)
    public HttpResult<List<RunManageVO>> getLineLedger(@RequestBody @Validated RunManageParam runManageParam) {
        String methodDescribe = getMethodDescribe("getLineLedger");
        List<RunManageVO> res = runManageService.getLineLedger(runManageParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getRuntimeData")
    @ApiOperation("终端台账信息")
    @ApiImplicitParam(name = "runManageParam", value = "终端台账参数", required = true)
    public HttpResult<List<RunTimeVO>> getRuntimeData(@RequestBody @Validated RunManageParam runManageParam) {
        String methodDescribe = getMethodDescribe("getRuntimeData");
        List<RunTimeVO> result = runManageService.getRuntimeDetail(runManageParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDeviceLedger")
    @ApiOperation("获取基本的终端台账信息")
    @ApiImplicitParam(name = "runManageParam", value = "终端台账参数", required = true)
    public HttpResult<Page<RunTimeVO>> getDeviceLedger(@RequestBody @Validated RunManageParam runManageParam) {
        String methodDescribe = getMethodDescribe("getRuntimeData");
        Page<RunTimeVO> result = runManageService.getDeviceLedger(runManageParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getTerminalLedger")
    @ApiOperation("终端台账统计")
    @ApiImplicitParam(name = "deviceInfoParam", value = "终端台账参数", required = true)
    public HttpResult<List<TerminalLedgerVO>> getTerminalLedger(@RequestBody @Validated DeviceInfoParam deviceInfoParam) {
        String methodDescribe = getMethodDescribe("getTerminalLedger");
        List<TerminalLedgerVO> result = runManageService.getTerminalLedger(deviceInfoParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

}
