package com.muyu.server.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.domain.Template;
import com.muyu.server.service.TemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * 报文模版管理
 * @author liuxinyue
 * @Package：com.template.controller
 * @Project：cloud-server-c
 * @name：TemplateController
 * @Date：2024/9/20 12:12
 */
@RestController
@RequestMapping("/template")
@AllArgsConstructor
@Tag(name = "报文模版管理",description = "报文模版管理")
@Log4j2
public class TemplateController {

    @Autowired
    private TemplateService templateService;


    /**
     * 报文模版列表
     * @return
     */
    @PostMapping("/templateList")
    @Operation(summary = "报文模版列表",description = "报文模版列表")
    public Result<List<Template>> templateList() {
        return Result.success(templateService.list());
    }


    /**
     * 解析报文
     * @param templateMessage
     * @return
     */
    @PostMapping("/messageParsing")
    @Operation(summary = "报文解析",description = "报文解析")
    public Result messageParsing(@RequestParam("templateMessage") String templateMessage) throws SQLException, IoTDBConnectionException, ClassNotFoundException, StatementExecutionException, ExecutionException, InterruptedException {
        templateService.messageParsing(templateMessage);
        return Result.success();
    }



}
