package com.ruoyi.web.app;

import org.springframework.beans.factory.annotation.Autowired;
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 com.ruoyi.bst.commandLog.domain.CommandLog;
import com.ruoyi.bst.commandLog.service.CommandLogService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.LogBizType;
import com.ruoyi.common.utils.StringUtils;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/app/commandLog")
public class AppCommandLogController extends BaseController {

    @Autowired
    private CommandLogService commandLogService;

    @ApiOperation("记录蓝牙发送命令日志")
    @PostMapping("/bluetooth")
    @Log(title = "记录蓝牙发送命令日志", businessType = BusinessType.INSERT, bizIdName = "arg0", bizType = LogBizType.COMMAND_LOG)
    public AjaxResult addBluetoothLog(@RequestBody CommandLog data) {
        // 去掉MAC号的前缀
        if (StringUtils.hasText(data.getMac())) {
            String[] split = data.getMac().split("-");
            if (split.length > 1) {
                data.setMac(split[1]);
            }
        }
        return toAjax(commandLogService.addBluetoothLog(data, getLoginUser()));
    }

}
