package com.njcn.csharmonic.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.csdevice.pojo.vo.DataGroupEventVO;
import com.njcn.csdevice.pojo.vo.EachModuleVO;
import com.njcn.csdevice.pojo.vo.RecordVo;
import com.njcn.csharmonic.param.DataParam;
import com.njcn.csharmonic.param.ItemParam;
import com.njcn.csharmonic.pojo.vo.AppLineDetailVo;
import com.njcn.csharmonic.service.IDataService;
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.web.bind.annotation.*;

import java.util.List;

/**
 * @author xy
 */
@Slf4j
@RestController
@RequestMapping("/data")
@Api(tags = "装置数据")
@AllArgsConstructor
public class DataController extends BaseController {

    private final IDataService dataService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/realTimeData")
    @ApiOperation("设备监控-》准实时数据")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<List<AppLineDetailVo>> realTimeData(@RequestBody DataParam param) {
        String methodDescribe = getMethodDescribe("realTimeData");
        List<AppLineDetailVo> list = dataService.getRealTimeData(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getTestData")
    @ApiOperation("设备监控-》测试项数据")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<List<RecordVo>> getTestData(@RequestBody DataParam param) {
        String methodDescribe = getMethodDescribe("getTestData");
        List<RecordVo> list = dataService.getTestData(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getEventByItem")
    @ApiOperation("方案数据-》根据测试项获取暂态事件")
    @ApiImplicitParam(name = "param", value = "param", required = true)
    public HttpResult<List<DataGroupEventVO>> getEventByItem(@RequestBody ItemParam param) {
        String methodDescribe = getMethodDescribe("getEventByItem");
        List<DataGroupEventVO> list = dataService.getEventByItem(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/allModelData")
    @ApiOperation("设备监控-》模块数据")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<List<EachModuleVO>> allModelData(@RequestBody DataParam param) {
        String methodDescribe = getMethodDescribe("allModelData");
        List<EachModuleVO> list = dataService.allModelData(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getModuleState")
    @ApiOperation("apf-》获取模块状态")
    @ApiImplicitParam(name = "id", value = "id", required = true)
    public HttpResult<List<EachModuleVO>> getModuleState(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getModuleState");
        List<EachModuleVO> list = dataService.getModuleState(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineDataByEngineer")
    @ApiOperation("App-》工程下所有监测点数据")
    @ApiImplicitParam(name = "id", value = "工程id", required = true)
    public HttpResult<List<AppLineDetailVo>> getLineDataByEngineer(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getLineDataByEngineer");
        List<AppLineDetailVo> list = dataService.getLineDataByEngineer(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

}
