package com.gyee.wisdom.alarm.sharding.controller;

import com.gyee.wisdom.alarm.sharding.cache.AlarmInfoCache;
import com.gyee.wisdom.alarm.sharding.entity.AlertKnowledge;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @descrition:预警专家知识
 * @author:Wanghs
 * @date:2020-07-14
 */
@RestController
@RequestMapping("/knowledge")
public class AlertKnowledgeController {

    @Autowired
    private AlarmInfoCache infoCache;

    @GetMapping(value = "/search")
    public List<AlertKnowledge> getKnowledge(@RequestParam(value = "alertText", required = true) String alertText) {
        List<AlertKnowledge> resultList = new ArrayList<>();

        //将数组转化为list;
        List<String> alertTextList = Arrays.asList(alertText.split(","));
        HashMap<String, AlertKnowledge> knowledgeHashMap = infoCache.getKnowledgeHashMap();
        for (String s : alertTextList) {
            if (knowledgeHashMap.containsKey(s)) {
                resultList.add(knowledgeHashMap.get(s));
            }
        }

        return resultList;

    }

}
