package com.aiotagro.cattletrade.business.controller;

import com.aiotagro.cattletrade.business.service.IotDeviceSyncService;
import com.aiotagro.common.core.web.domain.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.RestController;

/**
 * IoT设备数据同步控制器
 *
 * @author System
 * @date 2025-01-16
 */
@RestController
@RequestMapping("/iotSync")
public class IotDeviceSyncController {

    private static final Logger logger = LoggerFactory.getLogger(IotDeviceSyncController.class);

    @Autowired
    private IotDeviceSyncService iotDeviceSyncService;

    /**
     * 手动同步IoT设备数据
     */
    @PostMapping("/sync")
    public AjaxResult syncDeviceData() {
        try {
            logger.info("开始手动同步IoT设备数据");
            iotDeviceSyncService.syncIotDeviceData();
            logger.info("手动同步IoT设备数据完成");
            return AjaxResult.success("数据同步完成");
        } catch (Exception e) {
            logger.error("手动同步IoT设备数据失败", e);
            return AjaxResult.error("数据同步失败：" + e.getMessage());
        }
    }
}
