package com.kym.service.impl;

import com.kym.entity.DeviceRelation;
import com.kym.mapper.DeviceRelationMapper;
import com.kym.service.DeviceRelationService;
import com.kym.service.cache.KymCache;
import com.kym.service.mybatisplus.MyBaseServiceImpl;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author skyline
 * @since 2024-11-11
 */
@Service
public class DeviceRelationServiceImpl extends MyBaseServiceImpl<DeviceRelationMapper, DeviceRelation> implements DeviceRelationService {

    @PostConstruct
    private void init() {
        list().forEach(item -> {
            // 初始化短编号和设备信息的关联
            KymCache.INSTANCE.putWashShortId2ProductKeyAndDeviceName(Map.of(item.getShortId(), item.getProductKey() + "," + item.getDeviceName()));
            // shortId和stationId的对应关系
            KymCache.INSTANCE.putShortId2StationId(Map.of(item.getShortId(), item.getStationId()));
            // shortId和seqName的对应关系
            KymCache.INSTANCE.putShortId2SeqName(Map.of(item.getShortId(), item.getSeqName()));
        });
    }

}
