package com.njcn.csdevice.controller.data;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
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.controller.annotation.QueryBean;
import com.njcn.csdevice.param.LineCountEvaluateParam;
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
import com.njcn.csdevice.service.ICsCommunicateService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
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 hongawen
 * @version 1.0
 * @data 2024/11/6 19:48
 */
@Validated
@Slf4j
@Controller
@RestController
@RequestMapping("/pqsCommunicate")
@Api(tags = "获取装置上下线记录")
public class PqsCommunicateController extends BaseController {

    @QueryBean
    private ICsCommunicateService pqsCommunicateCvtQuery;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getRawDataLatest")
    @ApiOperation("获取取出最新装置数据")
    public HttpResult<List<PqsCommunicateDto>> getRawDataLatest(@RequestBody LineCountEvaluateParam lineParam) {
        String methodDescribe = getMethodDescribe("getRawDataLatest");
        List<PqsCommunicateDto> rawData = pqsCommunicateCvtQuery.getRawDataLatest(lineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rawData, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getRawData")
    @ApiOperation("获取原始数据")
    public HttpResult<List<PqsCommunicateDto>> getRawData(@RequestBody LineCountEvaluateParam lineParam) {
        String methodDescribe = getMethodDescribe("getRawData");
        List<PqsCommunicateDto> rawData = pqsCommunicateCvtQuery.getRawData(lineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rawData, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getRawDataEnd")
    @ApiOperation("获取是否有当天最后一条数据")
    public HttpResult<List<PqsCommunicateDto>> getRawDataEnd(@RequestBody LineCountEvaluateParam lineParam) {
        String methodDescribe = getMethodDescribe("getRawData");
        List<PqsCommunicateDto> rawData = pqsCommunicateCvtQuery.getRawDataEnd(lineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rawData, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/insertion")
    @ApiOperation("插入数据")
    public HttpResult<String> insertion(@RequestBody PqsCommunicateDto pqsCommunicateDto) {
        String methodDescribe = getMethodDescribe("insertion");
        pqsCommunicateCvtQuery.insertion(pqsCommunicateDto);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

}
