package com.securitycontrol.screen.service.impl;

import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.entity.screen.dto.ScreenParamDto;
import com.securitycontrol.entity.screen.vo.DtreeVo;
import com.securitycontrol.screen.mapper.IVideoMapper;
import com.securitycontrol.screen.service.IVideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author：cwchen
 * @date：2024-04-01-10:03
 * @version：1.0
 * @description：视频监控业务逻辑层
 */
@Service(value = "IVideoService")
@Slf4j
public class VideoServiceImpl implements IVideoService {

    @Resource(name = "IVideoMapper")
    private IVideoMapper mapper;

    @Override
    public AjaxResult getVideoTree(ScreenParamDto dto) {
        List<DtreeVo> list = new ArrayList<>();
        try {
            list = mapper.getVideoTree(dto);
            List<DtreeVo> sortDataList = list.stream().sorted(Comparator.comparing(DtreeVo::getOnLine, Comparator.reverseOrder())).collect(Collectors.toList());
            return AjaxResult.success(sortDataList);
        } catch (Exception e) {
            log.error("视频列表",e);
        }
        return AjaxResult.success(list);
    }
}
