package com.controllers;


import com.common.entity.AppLog;
import com.common.service.ElasticsearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/api/applog")
public class AppLogController {

    @Autowired
    private ElasticsearchService elasticsearchService;

    /**
     * 保存日志到ES
     */
    @PostMapping
    public String saveAppLog(@RequestBody AppLog appLog) {
        // 生成唯一ID（如果前端没有提供）
        if (appLog.getId() == null) {
            appLog.setId(UUID.randomUUID().toString());
        }

        elasticsearchService.saveAppLog(appLog);
        return "保存成功";
    }
}