package cd.casic.ci.api;

import cd.casic.ci.process.process.service.dataAnalysis.DataAnalysisService;
import cd.casic.framework.commons.pojo.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
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.net.URLDecoder;
import java.nio.charset.StandardCharsets;

/**
 * 数据分析 NUDT数据安全态势
 *
 * @author: Paul
 * @create: 2025-07-29 13:52
 */
@Tag(name = "NUDT数据安全态势")
@RestController
@RequestMapping("/dataAnalysis")
public class DataAnalysisController {

    @Resource
    private DataAnalysisService dataAnalysisService;

    @Operation(summary = "人数，任务次数，漏洞总数，高危漏洞 统计")
    @GetMapping("/userAndTaskCount")
    public CommonResult userAndTaskDataCount(@RequestParam(required = false, value = "city") String city) {
        if (city != null) {
            city = URLDecoder.decode(city, StandardCharsets.UTF_8);
        }
        return CommonResult.success(dataAnalysisService.getUserAndTaskDataCount(city));
    }

    @Operation(summary = "漏洞监测分布概览")
    @GetMapping("/HoopVulCount")
    public CommonResult HoopVulDataCount(@RequestParam(required = false, value = "city") String city) {
        return CommonResult.success(dataAnalysisService.getHoopVulCountList());
    }

    @Operation(summary = "资源分配数据概览")
    @GetMapping("/ResourceDistList")
    public CommonResult ResourceDistList(@RequestParam(required = false, value = "city") String city) {
        if (city != null) {
            city = URLDecoder.decode(city, StandardCharsets.UTF_8);
        }
        return CommonResult.success(dataAnalysisService.getResourceDistCountList(city));
    }

    @Operation(summary = "漏洞监测数据概览")
    @GetMapping("/VulMonitorDataList")
    public CommonResult VulMonitorDataList(@RequestParam(required = false, value = "city") String city) {
        if (city != null) {
            city = URLDecoder.decode(city, StandardCharsets.UTF_8);
        }
        return CommonResult.success(dataAnalysisService.getVulMonitorCountList(city));
    }

    @Operation(summary = "人数，任务次数，漏洞总数，高危漏洞 统计 列表")
    @GetMapping("/userAndTaskCountList")
    public CommonResult userAndTaskCountList(@RequestParam(required = false, value = "city") String city) {
        return CommonResult.success(dataAnalysisService.userAndTaskCountList(city));

    }
}
