package com.tuoheng.admin.service.camera.query;

import cn.hutool.core.collection.CollectionUtil;
import com.tuoheng.admin.entity.domain.Camera;
import com.tuoheng.admin.entity.request.camera.QueryCameraListRequest;
import com.tuoheng.admin.mapper.CameraMapper;
import com.tuoheng.common.utils.JsonResult;
import com.tuoheng.system.entity.User;
import com.tuoheng.system.utils.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 查询监控列表业务层处理
 *
 * @author wanjing
 * @team tuoheng
 * @date 2022-11-22
 */
@Slf4j
@Service
public class QueryCameraListService {

    @Autowired
    private CameraMapper cameraMapper;

    public JsonResult getList(QueryCameraListRequest request) {
//        log.info("进入查询监控列表业务");
        User user = ShiroUtils.getUserInfo();
        Integer tenantId = user.getTenantId();
        request.setTenantId(tenantId);

        JsonResult result = this.check(tenantId, request);
        if (0 != result.getCode()) {
            log.info("进入查询监控列表业务：校验失败：{}", result.getMsg());
            return result;
        }
        List<Camera> cameraList = cameraMapper.selectList(request);
        if (CollectionUtil.isEmpty(cameraList)) {
            log.info("监控列表数据为空");
        }
        return JsonResult.success(cameraList);
    }

    /**
     * 检查参数
     *
     * @param tenantId
     * @param request
     * @return
     */
    private JsonResult check(Integer tenantId, QueryCameraListRequest request) {
        return JsonResult.success();
    }

}
