package com.gyee.frame.service.knowledge;

import com.gyee.frame.model.auto.Alertrulefailure;
import com.gyee.frame.model.auto.P3DeviceFault;
import com.gyee.frame.model.custom.SimpleVo;
import com.gyee.frame.service.Alertrule2ervice;
import com.gyee.frame.service.AlertrulefailureService;
import com.gyee.frame.service.P3DeviceFaultService;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class KnowledgeService  {
    @Resource
    private P3DeviceFaultService p3DeviceFaultService;
    @Resource
    private Alertrule2ervice alertrule2ervice;
    @Resource
    private AlertrulefailureService alertrulefailureService;


    public  Map<String,Object> getAlertruleAllList() {

        Map<String,Object> map=new HashMap<>();
        List<P3DeviceFault> p3flist =  p3DeviceFaultService.findAll();
        if(!p3flist.isEmpty())
        {
            Map<String,Integer> gztxmap=new HashMap<>();
            for(P3DeviceFault pf:p3flist)
            {
                if(StringUtils.notEmp(pf.getDevicemodel()))
                {
                    String[] types=pf.getDevicemodel().split(",");

                    for(String str:types){

                        if(gztxmap.containsKey(str))
                        {
                            int temp=gztxmap.get(str);
                            temp++;
                            gztxmap.put(str,temp);
                        }else {
                            int temp=1;
                            gztxmap.put(str,temp);
                        }
                    }
                }

            }
            //故障体系
            map.put("gztx",gztxmap);

            List<SimpleVo> yjls=alertrule2ervice.getAlarmTypenum();
            Map<String,Integer> yjtxmap=new HashMap<>();
            if(!yjls.isEmpty())
            {
                for(SimpleVo vo:yjls)
                {
                    yjtxmap.put(vo.getName(),vo.getValue());
                }
            }
            //预警体系
            map.put("yjtx",yjtxmap);


            Map<String,Integer> tztxsmap=new HashMap<>();
            tztxsmap.put("clx",3);
            tztxsmap.put("fdj",5);
            tztxsmap.put("bi",1);
            tztxsmap.put("zk",2);
            //特征体系
            map.put("tztx",tztxsmap);

            List<Alertrulefailure> afls= alertrulefailureService.findAll();

            if(!afls.isEmpty())
            {
                Map<String,Integer> afmap=new HashMap<>();
                for(Alertrulefailure af:afls)
                {
                    if(afmap.containsKey(af.getModel()))
                    {
                        int temp=afmap.get(af.getModel());
                        temp++;
                        afmap.put(af.getModel(),temp);
                    }else {
                        int temp=1;
                        afmap.put(af.getModel(),temp);
                    }
                }
                //排查检修方案
                map.put("afmap",afmap);
            }
        }


        Map<String,Integer> xntxsmap=new HashMap<>();
        xntxsmap.put("nxpj",3);
        xntxsmap.put("jkpj",5);
        xntxsmap.put("gzzd",1);
        xntxsmap.put("zk",2);
        //性能体系
        map.put("xntx",xntxsmap);

        Map<String,Integer> rgznmap=new HashMap<>();
        rgznmap.put("jcs",2);
        rgznmap.put("sjwl",7);

        //人工智能
        map.put(" rgzn",rgznmap);
        return map;

    }



}
