package com.sckw.slope.detection.controller;

import com.alibaba.fastjson2.JSONObject;
import com.sckw.core.annotation.Log;
import com.sckw.core.web.response.HttpResult;
import com.sckw.log.TraceLog.TraceLog;
import com.sckw.slope.detection.model.param.OriginalDeviceQuery;
import com.sckw.slope.detection.model.param.ProjectLogQuery;
import com.sckw.slope.detection.service.LogService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lfdc
 * @description 日志Controller
 * @date 2023-10-30 17:10:28
 */
@Slf4j
@RestController
@RequestMapping("/log")
public class LogController {

    @Autowired
    LogService logService;

    @Log(description = "日志查询-分页")
    @RequestMapping(name = "日志查询-分页", value = "/select", method = RequestMethod.POST)
    public HttpResult select(@Valid @RequestBody ProjectLogQuery projectLogQuery, HttpServletRequest request) {
        log.info("日志查询-分页 select param:{}", JSONObject.toJSONString(projectLogQuery));
        return HttpResult.ok(logService.select(projectLogQuery, request));
    }

    /**
     * 获取操作类型
     * @param request
     * @return
     */
    @Log(description = "日志查询-操作类型")
    @RequestMapping(name = "日志查询-操作类型", value = "/selectType", method = RequestMethod.GET)
    public HttpResult selectType( HttpServletRequest request) {
        return logService.selectType(request);
    }


//    @Log(description = "日志查询-元数据日志")
    @TraceLog(description = "日志查询-元数据日志")
    @RequestMapping(name = "日志查询-元数据日志", value = "/selectMetadata", method = RequestMethod.POST)
    public HttpResult selectMetadata(@Valid @RequestBody OriginalDeviceQuery query , HttpServletRequest request) {
        return HttpResult.ok(logService.selectMetadata(query,request));
    }
}
