package com.kym.service.admin.impl;

import com.github.yulichang.base.MPJBaseServiceImpl;
import com.kym.entity.admin.AdminUserStation;
import com.kym.mapper.admin.AdminUserStationMapper;
import com.kym.service.admin.AdminUserStationService;
import com.kym.service.cache.KymCache;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 操作员站点关联表 服务实现类
 * </p>
 *
 * @author skyline
 * @since 2023-09-18
 */
@Service
public class AdminUserStationServiceImpl extends MPJBaseServiceImpl<AdminUserStationMapper, AdminUserStation> implements AdminUserStationService {

    @PostConstruct
    private void init() {
        var adminUser2Stations = list().stream().collect(Collectors.toMap(AdminUserStation::getAdminUserId,
                adminUserStation -> {
                    List<String> stationIds = new ArrayList<>();
                    stationIds.add(adminUserStation.getStationId());
                    return stationIds;
                },
                (v1, v2) -> {
                    v1.addAll(v2);
                    return v1;
                }
        ));

        KymCache.INSTANCE.putAdminUser2Stations(adminUser2Stations);
    }
}
