package com.xjrsoft.module.hikvision.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.xjrsoft.module.hikvision.entity.HikvisionData;
import com.xjrsoft.module.hikvision.mapper.HikvisionDataMapper;
import com.xjrsoft.module.hikvision.service.IHikvisionDataService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @title: 海康基础数据对照
 * @Author dzx
 * @Date: 2024年9月19日
 * @Version 1.0
 */

@Service
@AllArgsConstructor
public class HikvisionDataServiceImpl extends MPJBaseServiceImpl<HikvisionDataMapper, HikvisionData> implements IHikvisionDataService {

    @Override
    public String getHikvisionIdBySourceId(String sourceId) {
        return this.baseMapper.getHikvisionIdBySourceId(sourceId);
    }

    @Override
    public Map<String, String> getUserIdMap() {
        Map<String, String> result = new HashMap<>();
        List<HikvisionData> studentList = this.list(
                new QueryWrapper<HikvisionData>().lambda()
                        .eq(HikvisionData::getTableName, "base_student")
                        .isNotNull(HikvisionData::getSourceId)
                        .isNotNull(HikvisionData::getHikvisionId)
        );
        Map<String, String> studentMap = studentList.stream().collect(Collectors.toMap(HikvisionData::getHikvisionId, HikvisionData::getSourceId));
        result.putAll(studentMap);

        List<HikvisionData> teacherList = this.list(
                new QueryWrapper<HikvisionData>().lambda()
                        .eq(HikvisionData::getTableName, "base_teacher")
                        .isNotNull(HikvisionData::getSourceId)
                        .isNotNull(HikvisionData::getHikvisionId)
        );
        Map<String, String> teacherMap = teacherList.stream().collect(Collectors.toMap(HikvisionData::getHikvisionId, HikvisionData::getSourceId));
        result.putAll(teacherMap);
        return result;
    }
}
