package cn.iocoder.yudao.module.system.controller.admin.statistics;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.statistics.dto.RobotStatusClassificationDTO;
import cn.iocoder.yudao.module.system.controller.admin.statistics.dto.RobotTaskManualInterventionDTO;
import cn.iocoder.yudao.module.system.controller.admin.statistics.dto.RobotWarnMsgClassificationDTO;
import cn.iocoder.yudao.module.system.controller.admin.statistics.dto.RobotWorkHourStatisticsDTO;
import cn.iocoder.yudao.module.system.service.robot.RobotInformationService;
import cn.iocoder.yudao.module.system.service.robot.RobotTaskDetailService;
import cn.iocoder.yudao.module.system.service.robot.RobotWarnMsgService;
import cn.iocoder.yudao.module.system.service.statistics.RobotWorkingHoursStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 统计")
@RestController
@RequestMapping("/system/statistics")
@Validated
public class StatisticsController {

    @Resource
    private RobotInformationService informationService;

    @Resource
    private RobotTaskDetailService taskDetailService;

    @Resource
    private RobotWarnMsgService warnMsgService;

    @Resource
    private RobotWorkingHoursStatisticsService robotWorkingHoursStatisticsService;

    @GetMapping("/robotStatusClassification")
    @Operation(summary = "统计车辆状态分类")
    @PreAuthorize("@ss.hasPermission('robot:information:robotStatusClassification')")
    public CommonResult<RobotStatusClassificationDTO> robotStatusClassification() {
        return success(informationService.robotStatusClassification());
    }

    @GetMapping("/robotTaskAutomaticArtificial")
    @Operation(summary = "统计任务人工完成/自动完成" ,description = "type  1:周, 2:月,  3:季度")
    @PreAuthorize("@ss.hasPermission('robot:information:robotTaskAutomaticArtificial')")
    public CommonResult<RobotTaskManualInterventionDTO> robotTaskAutomaticArtificial(@RequestParam("type") String type) {
        return success(taskDetailService.robotTaskAutomaticArtificial(type));
    }

    @GetMapping("/robotWarnMsgClassification")
    @Operation(summary = "统计故障根因分析" ,description = "type  1:周, 2:月,  3:季度")
    @PreAuthorize("@ss.hasPermission('robot:information:robotWarnMsgClassification')")
    public CommonResult<Map<String,List<RobotWarnMsgClassificationDTO>>> robotWarnMsgClassification(@RequestParam("type") String type) {
        return success(warnMsgService.robotWarnMsgClassification(type));
    }

    @GetMapping("/robotWorkHourStatistics")
    @Operation(summary = "车辆工作时长统计" ,description = "type  1:周, 2:月,  3:季度 ;  positionMapId 地图Id")
    @PreAuthorize("@ss.hasPermission('robot:information:robotWorkHourStatistics')")
    public CommonResult<List<RobotWorkHourStatisticsDTO>> robotWorkHourStatistics(@RequestParam("type") String type,
                                                                                              @RequestParam("positionMapId") String positionMapId) {
        return success(robotWorkingHoursStatisticsService.robotWorkHourStatistics(type,positionMapId));
    }

}
