package com.usky.transfer.controller.api;

import com.usky.common.core.bean.ApiResult;
import com.usky.transfer.RemoteTransferService;
import com.usky.transfer.domain.*;
import com.usky.transfer.service.DmpProductService;
import com.usky.transfer.service.QueryInfluxdbDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class DataTransferControllerApi implements RemoteTransferService {

    @Autowired
    private QueryInfluxdbDataService queryInfluxdbDataService;
    @Autowired
    private DmpProductService dmpProductService;

    /**
     * 删除产品缓存信息
     */
    @Override
    public ApiResult<Void> deleteProductCache(){
        dmpProductService.deleteProductCache();
        return ApiResult.success();
    }

    /**
     * 删除设备缓存信息
     */
    @Override
    public ApiResult<Void> deleteDeviceCache(String productCode){
        dmpProductService.deleteDeviceCache(productCode);
        return ApiResult.success();
    }

    /**
     * 单个设备数据写入
     * @return
     */
    @Override
    public ApiResult<Void> sendDeviceData(DeviceDataWriteVO writeVO){
        queryInfluxdbDataService.sendDeviceDataToMQ(writeVO);
        return ApiResult.success();
    }

    /**
     * 下发单个设备控制命令
     */
    @Override
    public Map<String,Object> deviceControl(String productCode, String deviceUuid, String commandStr,Integer tenantId, Long userId, String userName){
        return queryInfluxdbDataService.deviceControl(productCode, deviceUuid, commandStr, tenantId, userId, userName);
    }
}
