package com.sooka.mainpage.service.impl;

import com.business.domain.TJ_dept_table;
import com.sooka.mainpage.domain.InterfaceCallCount_Bean;
import com.sooka.mainpage.domain.Qssjgxqk_Bean;
import com.sooka.mainpage.mapper.MainPageMapper;
import com.sooka.mainpage.mapper.MainPage_Gjj_Mapper;
import com.sooka.mainpage.service.MainPageService;
import com.sooka.system.mapper.TUInterfaceinfoMapper;
import org.springframework.stereotype.Service;

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

@Service
public class MainPageServiceImpl implements MainPageService {

    @Resource
    MainPageMapper mainPageMapper;

    @Resource
    MainPage_Gjj_Mapper mainPage_gjj_mapper;

    @Resource
    TUInterfaceinfoMapper tuInterfaceinfoMapper;

    @Override
    public Map getVisualization() {


        Map map = new HashMap();
        List<InterfaceCallCount_Bean> interfaceCallCount_List = mainPageMapper.interfaceCallCount();
        map.put("interfaceCallCount_List", interfaceCallCount_List);
        List<Qssjgxqk_Bean> qssjgxqk_List = mainPageMapper.qssjgxqk();
        map.put("qssjgxqk_List", qssjgxqk_List);
        //共享接口总数//归集接口总数
        int zb_guiji = 0;
        int zb_gongxiang = 0;
        for (int i = 0; i < qssjgxqk_List.size(); i++) {
            Qssjgxqk_Bean b = qssjgxqk_List.get(i);
            zb_guiji += b.getGj_cou();
            zb_gongxiang += b.getGx_cou();
        }
        int tj_interface_total = zb_guiji + zb_gongxiang;
        map.put("zb_guiji", zb_guiji);
        map.put("zb_gongxiang", zb_gongxiang);
        //接口总数、调用频次、归集频次、共享频次、接入部门、接口故障
        int tj_dypc = 0;
        int tj_gxpc = 0;
        int tj_gjpc = 0;
        for (int i = 0; i < interfaceCallCount_List.size(); i++) {
            InterfaceCallCount_Bean b = interfaceCallCount_List.get(i);
            tj_gjpc += b.getCou_gj();
            tj_gxpc += b.getCou_gx();
        }
        tj_dypc = tj_gxpc + tj_gjpc;

        map.put("tj_interface_total", tj_interface_total);
        map.put("tj_dypc", tj_dypc);
        map.put("tj_gjpc", tj_gjpc);
        map.put("tj_gxpc", tj_gxpc);
        map.put("tj_jrbm", interfaceCallCount_List.size());
        map.put("tj_jkgz", 0);

        //接口使用频次- 日
        List interfacePinci_day_list = mainPageMapper.getInterfacePinci_day();
        map.put("interfacePinci_day_list", interfacePinci_day_list);


        //市接口中台数据总数
        Long tj_sjkzt_sjgs = 0L;
        for (int i = 0; i < qssjgxqk_List.size(); i++) {
            List<TJ_dept_table> tables = mainPageMapper.getTableNamesBydeptId(qssjgxqk_List.get(i).getDept_id());
            Integer count = 0;
            if (qssjgxqk_List.get(i).getDept_id() == 206) {
                //公积金
                for (int j = 0; j < tables.size(); j++) {
                    String table_name = tables.get(j).getTable_name();
                    Integer c = mainPage_gjj_mapper.countNumFromDept(table_name);
                    count += c;
                    tj_sjkzt_sjgs += c;
                }
            } else {
                //其他
                for (int j = 0; j < tables.size(); j++) {
                    String table_name = tables.get(j).getTable_name();
                    Integer c = mainPageMapper.countNumFromDept(table_name);
                    count += c;
                    tj_sjkzt_sjgs += c;
                }
            }
            qssjgxqk_List.get(i).setDept_record_count(count);
            map.put("tj_sjkzt_sjgs", tj_sjkzt_sjgs);
        }

        //接口占比
        Integer interface_status_0 = mainPageMapper.getInterfaceStatusCount("0");
        Integer interface_status_1 = mainPageMapper.getInterfaceStatusCount("1");

        map.put("interface_status_0",interface_status_0);
        map.put("interface_status_1",interface_status_1);

        //共享平台接口总数
        Integer GXPT_jkzs = mainPageMapper.getGXPT_jkzs();
        map.put("GXPT_jkzs",GXPT_jkzs);
        return map;
    }


}
