package com.ruoyi.web.controller.app;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ss.commandLog.domain.CommandLog;
import com.ruoyi.ss.commandLog.service.ICommandLogService;
import io.swagger.annotations.ApiOperation;
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;

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

    @Autowired
    private ICommandLogService commandLogService;

    @ApiOperation("记录蓝牙发送命令日志")
    @PostMapping("/bluetooth")
    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()));
    }

}
