|
@@ -0,0 +1,78 @@
|
|
|
+package com.gyee.wisdom.service;
|
|
|
+
|
|
|
+import com.gyee.wisdom.model.TagPoint;
|
|
|
+import com.opencsv.bean.CsvToBeanBuilder;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class CacheService {
|
|
|
+
|
|
|
+ private int[] tagIds;
|
|
|
+
|
|
|
+ public int[] getTagIds() {
|
|
|
+ if (tagIds == null)
|
|
|
+ {
|
|
|
+ List<TagPoint> tps = getPointTags();
|
|
|
+ if (tps != null && tps.size() > 0) {
|
|
|
+ tagIds = tps.stream().mapToInt(t-> Integer.parseInt(t.getTagId())).toArray();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return tagIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ private HashMap<Integer, TagPoint> tagPointMap;
|
|
|
+
|
|
|
+ public HashMap<Integer, TagPoint> getTagPointMap() {
|
|
|
+ if (tagPointMap == null) {
|
|
|
+ List<TagPoint> tps = getPointTags();
|
|
|
+ tagPointMap = new HashMap<>();
|
|
|
+ if (tps != null && tps.size() > 0) {
|
|
|
+ for(TagPoint tp : tps) {
|
|
|
+ Integer id = Integer.parseInt(tp.getTagId());
|
|
|
+ if (tagPointMap.containsKey(id) == false)
|
|
|
+ tagPointMap.put(id, tp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return tagPointMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<TagPoint> pointTags;
|
|
|
+
|
|
|
+ public List<TagPoint> getPointTags() {
|
|
|
+ if (pointTags == null)
|
|
|
+ pointTags = createPointTags();
|
|
|
+
|
|
|
+ return pointTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TagPoint> createPointTags() {
|
|
|
+ try {
|
|
|
+ Resource resource = new ClassPathResource("tag-point.csv");
|
|
|
+ InputStream ins = resource.getInputStream();
|
|
|
+ BufferedReader reader = new BufferedReader(new InputStreamReader(ins, "UTF-8"));
|
|
|
+ return new CsvToBeanBuilder(reader)
|
|
|
+ .withType(TagPoint.class).withSeparator(',').build().parse();
|
|
|
+
|
|
|
+ } catch (Exception ex) {
|
|
|
+ log.error(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|