package com.tievd.jyz.cache; import com.tievd.jyz.entity.SysCarPlace; import com.tievd.jyz.service.ISysCarPlaceService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * Author: wqy * Date: 2023/4/20 15:54 */ @Component public class CarPlaceCache { private static Map placeMap = new HashMap<>(); @Autowired ISysCarPlaceService carPlaceService; @PostConstruct private void init(){ List carPlaces = carPlaceService.list(); placeMap = carPlaces.stream().collect(Collectors.toMap(SysCarPlace::getLicenseNum, SysCarPlace::getLicensePlace)); } public static String getPlace(String carNumber) { return placeMap.getOrDefault(carNumber, "未知地区"); } }