WebMonitorInfoController.java 20.1 KB
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
package com.lhcredit.project.webbusiness.controller;


import com.fasterxml.jackson.core.type.TypeReference;
import com.lhcredit.common.utils.JsonUtils;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.framework.aspectj.lang.annotation.CheckToken;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.domain.AjaxResult;
import com.lhcredit.project.business.frontUser.domain.FrontUser;
import com.lhcredit.project.business.frontUser.domain.FrontUserMon;
import com.lhcredit.project.business.frontUser.domain.TempConf;
import com.lhcredit.project.business.frontUser.service.IFrontUserService;
import com.lhcredit.project.business.monitorCompanyNew.domain.MonitorCompanyNew;
import com.lhcredit.project.business.monitorCompanyNew.service.IMonitorCompanyNewService;
import com.lhcredit.project.business.monitorCompanyNew.vo.MonitorCompanyNewVo;
import com.lhcredit.project.business.monitorInfo.domain.MonitorInfo;
import com.lhcredit.project.business.monitorInfo.domain.MonitorInfoNum;
import com.lhcredit.project.business.monitorInfo.service.IMonitorInfoService;
import com.lhcredit.project.business.monitorInfoNew.domain.MonitorInfoNew;
import com.lhcredit.project.business.monitorInfoNew.service.IMonitorInfoNewService;
import com.lhcredit.project.business.monitorValue.domain.MonitorValue;

import com.lhcredit.project.business.monitorValue.service.IMonitorValueService;

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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 监控数据查询
 */
@RestController
@RequestMapping("/web/monitorInfo")
public class WebMonitorInfoController extends BaseController {

    @Autowired
    private IMonitorInfoService monitorInfoService;

    @Autowired
    private IMonitorValueService monitorValueService;

    @Autowired
    private IMonitorInfoNewService monitorInfoNewService;

    @Autowired
    private IFrontUserService frontUserService;

    @Autowired
    private IMonitorCompanyNewService monitorCompanyNewService;
    /**
     * 根据类型,查询数量
     * @param begin
     * @param end
     * @return
     */
    @CheckToken
    @ResponseBody
    @GetMapping("/getAllNum")
    public AjaxResult getAllNum(String begin,String end){
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        Map resultMap=new HashMap();
        List<Map> list=new ArrayList<>();
        //查询动态监控总数
        List<Map<String,String>> groupMap=monitorInfoService.getGroupBy(userId,begin,end);
        Map tjMap=new HashMap<>();//统计map
        for(Map<String,String> tj:groupMap) {
            String level=tj.get("warningLevel");
            if (level.equals("gfx")) {
                tjMap.put("gfx",   tj.get("ct"));
            } else if(level.equals("zfx")) {
                tjMap.put("zfx", tj.get("ct"));
            } else if(level.equals("gz")) {
                tjMap.put("gz",tj.get("ct"));
            }else if (level.equals("ts")) {
                tjMap.put("ts", tj.get("ct"));
            }
        }
        int yzjg=tjMap.containsKey("gfx")==true? Integer.parseInt(tjMap.get("gfx").toString()):0;
        int jg=tjMap.containsKey("zfx")==true? Integer.parseInt(tjMap.get("zfx").toString()):0;
        int gz=tjMap.containsKey("gz")==true? Integer.parseInt(tjMap.get("gz").toString()):0;
        int ts=tjMap.containsKey("ts")==true? Integer.parseInt(tjMap.get("ts").toString()):0;
        if(yzjg==0){
            tjMap.put("gfx", "0");
        }
        if(jg==0){
            tjMap.put("zfx","0");
        }
        if(gz==0){
            tjMap.put("gz","0");
        }
        if(ts==0){
            tjMap.put("ts","0");
        }
        int count=yzjg+jg+gz+ts;
        tjMap.put("count",  String.valueOf(count));//总数
        //查询动态企业数量
        Map<String, String> numMap=new HashMap<>();
        String comNum=monitorInfoService.getCompanyCount(userId,begin,end);
        numMap.put("comNum",comNum);

        //饼状图数据
        Map<String,String> pancakeMap=new HashMap<>();
//        List<Map<String,String>> allMap=monitorInfoService.getGroupBy(userId,null,null);//查询所有
//        for(Map all:allMap) {
//            String level=all.get("warningLevel").toString();
//            if (level.equals("yzjg")) {
//                Double yzjgRatio = yzjg / Double.parseDouble(all.get("ct").toString());
//                pancakeMap.put("yzjgRatio", String.format("%.2f", yzjgRatio));
//            }else if (level.equals("jg")) {
//                Double jgRatio = jg/ Double.parseDouble(all.get("ct").toString());
//                pancakeMap.put("jgRatio", String.format("%.2f", jgRatio));
//            }else if (level.equals("gz")) {
//                Double gzRatio = gz / Double.parseDouble(all.get("ct").toString());
//                pancakeMap.put("gzRatio", String.format("%.2f", gzRatio));
//            }else if (level.equals("ts")) {
//                Double tsRatio = ts / Double.parseDouble(all.get("ct").toString());
//                pancakeMap.put("tsRatio", String.format("%.2f", tsRatio));
//            }
//        }
        if(count==0){
            pancakeMap.put("gfxRatio", "0");
            pancakeMap.put("zfxRatio", "0");
            pancakeMap.put("gzRatio", "0");
            pancakeMap.put("tsRatio", "0");
        }else {


            Double tsRatio = ts / Double.parseDouble(String.valueOf(count));
            if(tsRatio>0.6){
                pancakeMap.put("tsRatio", "0.6");
                if(yzjg>0){
                    pancakeMap.put("gfxRatio", String.format("%.2f", 0.4*yzjg/(jg+gz+yzjg)));
                }else {
                    pancakeMap.put("gfxRatio", "0");
                }
                if(jg>0){
                    pancakeMap.put("zfxRatio", String.format("%.2f", 0.4*jg/(jg+gz+yzjg)));
                }else {
                    pancakeMap.put("zfxRatio", "0");
                }
                if(gz>0){
                    pancakeMap.put("gzRatio", String.format("%.2f", 0.4*gz/(jg+gz+yzjg)));
                }else {
                    pancakeMap.put("gzRatio", "0");
                }

            }else {
                pancakeMap.put("tsRatio", String.format("%.2f", tsRatio));

                Double yzjgRatio = yzjg / Double.parseDouble(String.valueOf(count));
                pancakeMap.put("gfxRatio", String.format("%.2f", yzjgRatio));

                Double jgRatio = jg / Double.parseDouble(String.valueOf(count));
                pancakeMap.put("zfxRatio", String.format("%.2f", jgRatio));

                Double gzRatio = gz / Double.parseDouble(String.valueOf(count));
                pancakeMap.put("gzRatio", String.format("%.2f", gzRatio));

            }
        }
        resultMap.put("tjMap",tjMap);
        resultMap.put("numMap",numMap);
        resultMap.put("pancakeMap",pancakeMap);

        return AjaxResult.success(resultMap);
    }

    /**
     * 查询维度类型数据
     * @return
     */
    @CheckToken
    @ResponseBody
    @GetMapping("/getMonitorType")
    public AjaxResult getMonitorType(){
        return AjaxResult.success(monitorInfoNewService.getMonitorType());
    }


    /**
     * 根据类型,查询数量
     * @param begin
     * @param end
     * @return
     */
    @CheckToken
    @ResponseBody
    @GetMapping("/getAllNumNew")
    public AjaxResult getAllNumNew(String begin,String end){
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        Map resultMap=new HashMap();

        //查询动态企业数量
        Map<String, String> numMap=new HashMap<>();
        String activeEnterpriseCount=monitorInfoNewService.getCompanyCount(userId,begin,end);
        numMap.put("activeEnterpriseCount",activeEnterpriseCount);

        //查询动态总数
        String dynamicTotal=monitorInfoNewService.getCompanyNum(userId,begin,end);
        numMap.put("dynamicTotal",dynamicTotal);

        //监控企业数量
        MonitorCompanyNew monitorCompanyNew1 = new MonitorCompanyNew();
        monitorCompanyNew1.setUserId(userId);
        monitorCompanyNew1.setMonitorStatus("0");
        List<MonitorCompanyNewVo> monitorCompanyNewVos = monitorCompanyNewService.selectMonitorCompanyNewList(monitorCompanyNew1);
        int monitorCompanyNewVosSize = monitorCompanyNewVos.size();

        numMap.put("monitorEnterprise",monitorCompanyNewVosSize + "");


        //查询动态监控总数
        List<MonitorInfoNew> groupMap=monitorInfoNewService.getGroupBy(userId,begin,end);

        // 根据type分组,统计不同风险维度分布的个数
        Map<String, Long> riskDimensionDistribution = groupMap.stream()
                .collect(Collectors.groupingBy(
                        MonitorInfoNew::getType,  // 按type字段分组
                        Collectors.counting()     // 统计每种type的数量
                ));



        Map<String, Object> riskLevelTrendMap=new HashMap<>();
        // 根据 warningLevel 分组并计算每个组的个数
        Map<String, Long> warningLevelCountMap = groupMap.stream()
                .collect(Collectors.groupingBy(
                        MonitorInfoNew::getWarningLevel,  // 根据 warningLevel 分组
                        Collectors.counting()             // 计算每组的个数
                ));

        // 按天分组,并统计每天不同warningLevel的数量
        Map<LocalDate, Map<String, Long>> riskLevelTrend = groupMap.stream()
                .collect(Collectors.groupingBy(
                        // 按storageTime日期分组
                        monitorInfo -> monitorInfo.getStorageTime().toInstant()
                                .atZone(ZoneId.systemDefault())
                                .toLocalDate(),
                        // 统计每天不同warningLevel的数量
                        Collectors.groupingBy(
                                MonitorInfoNew::getWarningLevel,
                                Collectors.counting()
                        )
                ));
        // 使用TreeMap确保日期按正序排列
        Map<LocalDate, Map<String, Long>> sortedRiskLevelTrend = new TreeMap<>(riskLevelTrend);
        riskLevelTrendMap.put("riskLevelTrend", sortedRiskLevelTrend);
        riskLevelTrendMap.put("warningLevelCountMap", warningLevelCountMap);

        Map<String, Object> riskDimensionTrendMap=new HashMap<>();
        Map<String, Long> riskDimensionTrendCount = groupMap.stream()
                .collect(Collectors.groupingBy(
                        MonitorInfoNew::getType,  // 统计每天不同type的数量
                        Collectors.counting()             // 计算每组的个数
                ));

        // 根据storageTime按天分组,再统计每天type不同类型的个数
        Map<LocalDate, Map<String, Long>> riskDimensionTrend = groupMap.stream()
                .collect(Collectors.groupingBy(
                        // 按storageTime日期分组
                        monitorInfo -> monitorInfo.getStorageTime().toInstant()
                                .atZone(ZoneId.systemDefault())
                                .toLocalDate(),
                        // 统计每天不同type的数量
                        Collectors.groupingBy(
                                MonitorInfoNew::getType,
                                Collectors.counting()
                        )
                ));
        // 使用TreeMap确保日期按正序排列
        Map<LocalDate, Map<String, Long>> sortedRiskDimensionTrend = new TreeMap<>(riskDimensionTrend);
        riskDimensionTrendMap.put("riskDimensionTrendCount", riskDimensionTrendCount);
        riskDimensionTrendMap.put("riskDimensionTrend", sortedRiskDimensionTrend);


        resultMap.put("numMap",numMap);
        resultMap.put("riskDimensionDistribution",riskDimensionDistribution);
        resultMap.put("riskLevelTrendMap",riskLevelTrendMap);
        resultMap.put("riskDimensionTrendMap",riskDimensionTrendMap);

        return AjaxResult.success(resultMap);
    }
    /**
     * 根据企业变化查询数量
     * @param begin
     * @param end
     * @param warningLevel
     * @return
     */
    //分类查询数量
    @CheckToken
    @ResponseBody
    @GetMapping("/getWarningLevel")
    public AjaxResult getWarningLevel(String begin,String end,String warningLevel){
        if(StringUtils.isEmpty(warningLevel)){
            warningLevel="gfx";
        }
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        List<Map<String,Integer>> typeMap=monitorInfoService.getWarningLevel(userId,begin,end,warningLevel);

        return AjaxResult.success(typeMap);
    }

    /**
     * 查询分类数量
     * @param monitorInfoNum
     * @return
     */
    //查询分类数据
    @CheckToken
    @ResponseBody
    @GetMapping("/getListData")
    //String userId,String begin,String end,String warningLevel
    public AjaxResult getListData(MonitorInfoNum monitorInfoNum){
        if(StringUtils.isEmpty(monitorInfoNum.getWarningLevel())){
            monitorInfoNum.setWarningLevel("yzjg");
            monitorInfoNum.setUserId(String.valueOf(1));
        }
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        monitorInfoNum.setUserId(userId);
        startPage();
        List<MonitorInfoNum> list=monitorInfoService.getList(monitorInfoNum);
        return toAjax(list);
    }

    /**
     * 查询分类数量
     * @param monitorInfoNum
     * @return
     */
    //查询分类数据
    @CheckToken
    @ResponseBody
    @GetMapping("/getListDataNew")
    //String userId,String begin,String end,String warningLevel
    public AjaxResult getListDataNew(MonitorInfoNum monitorInfoNum){
        /*if(StringUtils.isEmpty(monitorInfoNum.getWarningLevel())){
            monitorInfoNum.setWarningLevel("gfx");
            monitorInfoNum.setUserId(String.valueOf(1));
        }*/
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        monitorInfoNum.setUserId(userId);
        startPage();
        List<MonitorInfoNum> list=monitorInfoNewService.getList(monitorInfoNum);
        return toAjax(list);
    }


    /**
     * 查询企业监控数据,根据等级
     * @param monitorInfo
     * @return
     */
    @CheckToken
    @ResponseBody
    @GetMapping("/getListLevel")
    public AjaxResult getListLevel(MonitorInfo monitorInfo){
//        if(StringUtils.isEmpty(monitorInfo.getWarningLevel())){
//            monitorInfo.setWarningLevel("yzjg");
//        }
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        monitorInfo.setUserId(userId);
        MonitorValue mv=new MonitorValue();
        mv.setStatus("0");
        mv.setType(monitorInfo.getType());
        List<Map> ltMV=monitorValueService.queryMonitorValueList(mv);

        startPage();
        List<MonitorInfo> list=monitorInfoService.getListLevel(monitorInfo);
        return toAjaxMvs(list,ltMV);
    }



    /**
     * 查询企业监控数据,根据等级
     * @param monitorInfo
     * @return
     */
    @CheckToken
    @ResponseBody
    @GetMapping("/getListLevelNew")
    public AjaxResult getListLevelNew(MonitorInfo monitorInfo){
//        if(StringUtils.isEmpty(monitorInfo.getWarningLevel())){
//            monitorInfo.setWarningLevel("gfx");
//        }
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        monitorInfo.setUserId(userId);
        MonitorValue mv=new MonitorValue();
        mv.setStatus("0");
        mv.setType(monitorInfo.getType());
        List<Map> ltMV=monitorValueService.queryMonitorValueListNew(mv);

        startPage();
        List<MonitorInfo> list=monitorInfoService.getListLevelNew(monitorInfo);
        return toAjaxMvs(list,ltMV);
    }

    /**
     * 查询加载有数据的分类
     * @param begin
     * @param end
     * @return
     */
    @CheckToken
    @ResponseBody
    @GetMapping("/getTypeData")
    public AjaxResult getTypeData(String begin,String end){
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        List<Map<String,String>> list=monitorInfoService.getTypeData(userId,begin,end);
        return AjaxResult.success(list);
    }


    /**
     * 查询加载有数据的分类
     * @param warningLevel
     * @param begin
     * @param end
     * @return
     */
    @CheckToken
    @ResponseBody
    @GetMapping("/getTypeDataNew")
    public AjaxResult getTypeDataNew(String begin,String end,String warningLevel){
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        List<Map<String,String>> list=monitorInfoService.getTypeDataNew(userId,begin,end, warningLevel);
        return AjaxResult.success(list);
    }

    /**
     * 查询监控企业数据
     * @param companyName
     * @param begin
     * @param end
     * @return
     */
    @CheckToken
    @ResponseBody
    @GetMapping("/getCompany")
    public AjaxResult getCompany(String begin,String end,String companyName){
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        List result=new LinkedList();
        List<Map<String,String>> list=monitorInfoService.getCompanyByType(userId,begin,end,companyName);
        for(Map map:list){
            String ename=map.get("companyName").toString();
            String[] monitor_col=map.get("monitor_col").toString().split(",");
            Map m=new HashMap();
            m.put("ename",ename);
            List lt=new ArrayList();
            for(int i=0;i<monitor_col.length;i++){
                String str=monitor_col[i];
                Map m1=new HashMap();
                m1.put("typeName",str.substring(0,str.indexOf("@")));
                m1.put("type",str.substring(str.indexOf("@")+1,str.length()));
                lt.add(m1);
            }
            m.put("typeList",lt);
            result.add(m);
        }

        return AjaxResult.success(result);
    }



    /**
     * 查询监控企业数据
     * @param companyName
     * @param begin
     * @param end
     * @return
     */
    @CheckToken
    @ResponseBody
    @GetMapping("/getCompanyNew")
    public AjaxResult getCompanyNew(String begin,String end,String companyName){
        FrontUserMon fum=getUserInfo();
        String userId=fum.getId().toString();
        List result=new LinkedList();
        List<Map<String,String>> list=monitorInfoService.getCompanyNewByType(userId,begin,end,companyName);
        for(Map map:list){
            String ename=map.get("companyName").toString();
            String[] monitor_col=map.get("monitor_col").toString().split(",");
            Map m=new HashMap();
            m.put("ename",ename);
            List lt=new ArrayList();
            for(int i=0;i<monitor_col.length;i++){
                String str=monitor_col[i];
                Map m1=new HashMap();
                m1.put("typeName",str.substring(0,str.indexOf("@")));
                m1.put("type",str.substring(str.indexOf("@")+1,str.length()));
                lt.add(m1);
            }
            m.put("typeList",lt);
            result.add(m);
        }

        return AjaxResult.success(result);
    }

    public static void main(String[] args) {
        List l1=new ArrayList();

//        Map m1=new HashMap();
//        m1.put("ename","aa企业");
//        List<Map> l2=new ArrayList();
//        Map m2=new HashMap();
//        m2.put("k","民事案件");
//        m2.put("v","111");
//        l2.add(m2);
//        m1.put("List",l2);
//        l1.add(m1);

//        for(int i=0;i<4;i++){
//            Map m1=new HashMap();
//            m1.put("ename","企业 "+i);
//            List<Map> l2=new ArrayList();
//            Map m2=new HashMap();
//            m2.put("k","民事案件"+i);
//            m2.put("v",i);
//            l2.add(m2);
//            m1.put("List",l2);
//
//            l1.add(m1);
//        }
        String str="发到@456";


        System.out.println(str.substring(0,str.indexOf("@")));
        System.out.println(str.substring(str.indexOf("@")+1,str.length()));
    }

}