package com.usky.iot.controller.web;


import com.usky.alarm.RemoteWebSocketService;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.iot.domain.BaseAppInfo;
import com.usky.iot.service.BaseAppInfoService;
import com.usky.iot.service.vo.AppInfoRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * APP用户心跳信息 前端控制器
 * </p>
 *
 * @author han
 * @since 2024-03-29
 */
@RestController
@RequestMapping("/baseAppInfo")
public class BaseAppInfoController {
    @Autowired
    private BaseAppInfoService baseAppInfoService;

    @Autowired
    private RemoteWebSocketService remoteWebSocketService;

    /**
     * 新增
     * @param baseAppInfo
     * @return
     */
    @PostMapping("add")
    public ApiResult<Void> add(@RequestBody BaseAppInfo baseAppInfo){
        baseAppInfoService.add(baseAppInfo);
        return ApiResult.success();
    }

    /**
     * 分页
     * @param appInfoRequest
     * @return
     */
    @PostMapping("/page")
    public ApiResult<CommonPage<BaseAppInfo>> page(@RequestBody AppInfoRequest appInfoRequest)
    {
        return ApiResult.success(baseAppInfoService.page(appInfoRequest));
    }

    /**
     * 自检
     * @param baseAppInfo
     * @return
     */
    @PostMapping("/selfCheck")
    public ApiResult<Void> selfCheck(@RequestBody String baseAppInfo){
        remoteWebSocketService.selfCheck(baseAppInfo);
        baseAppInfoService.selfCheck(baseAppInfo);
        return ApiResult.success();
    }

}

