zxl
2026-03-25 74e332504d98caaf8fab951d7d24be762b169f49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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<String, String> placeMap = new HashMap<>();
    
    @Autowired
    ISysCarPlaceService carPlaceService;
    
    @PostConstruct
    private void init(){
        List<SysCarPlace> carPlaces = carPlaceService.list();
        placeMap = carPlaces.stream().collect(Collectors.toMap(SysCarPlace::getLicenseNum, SysCarPlace::getLicensePlace));
    }
    
    public static String getPlace(String carNumber) {
        return placeMap.getOrDefault(carNumber, "未知地区");
    }
    
}