package com.aucma.production.controller;

import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.production.domain.dto.AndonDashboardDTO;
import com.aucma.production.service.IAndonDashboardService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 安灯生产监控看板Controller
 * 
 * 提供生产进度、效率监控、OEE数据、设备状态、品质数据等接口
 * 
 * @author Yinq
 * @date 2025-12-30
 */
@RestController
@RequestMapping("/production/andon/dashboard")
public class AndonDashboardController extends BaseController {

    @Autowired
    private IAndonDashboardService andonDashboardService;

    /**
     * 获取完整的看板数据
     * 
     * @param productLineCode 产线编码（可选）
     * @return 看板数据
     */
    @GetMapping("/all")
    public AjaxResult getDashboardData(@RequestParam(required = false) String productLineCode) {
        AndonDashboardDTO data = andonDashboardService.getDashboardData(productLineCode);
        return AjaxResult.success(data);
    }

    /**
     * 获取设备状态统计
     * 
     * @param productLineCode 产线编码（可选）
     * @return 设备状态统计
     */
    @GetMapping("/device-status")
    public AjaxResult getDeviceStatusSummary(@RequestParam(required = false) String productLineCode) {
        AndonDashboardDTO.DeviceStatusSummary data = andonDashboardService.getDeviceStatusSummary(productLineCode);
        return AjaxResult.success(data);
    }

    /**
     * 获取任务完成情况
     * 
     * @param productLineCode 产线编码（可选）
     * @return 任务完成情况
     */
    @GetMapping("/task-completion")
    public AjaxResult getTaskCompletionSummary(@RequestParam(required = false) String productLineCode) {
        AndonDashboardDTO.TaskCompletionSummary data = andonDashboardService.getTaskCompletionSummary(productLineCode);
        return AjaxResult.success(data);
    }

    /**
     * 获取OEE数据
     * 
     * @param productLineCode 产线编码（可选）
     * @return OEE数据
     */
    @GetMapping("/oee")
    public AjaxResult getOeeSummary(@RequestParam(required = false) String productLineCode) {
        AndonDashboardDTO.OeeSummary data = andonDashboardService.getOeeSummary(productLineCode);
        return AjaxResult.success(data);
    }

    /**
     * 获取利用率统计
     * 
     * @param productLineCode 产线编码（可选）
     * @return 利用率统计
     */
    @GetMapping("/utilization")
    public AjaxResult getUtilizationSummary(@RequestParam(required = false) String productLineCode) {
        AndonDashboardDTO.UtilizationSummary data = andonDashboardService.getUtilizationSummary(productLineCode);
        return AjaxResult.success(data);
    }

    /**
     * 获取品质数据
     * 
     * @param productLineCode 产线编码（可选）
     * @return 品质数据
     */
    @GetMapping("/quality")
    public AjaxResult getQualitySummary(@RequestParam(required = false) String productLineCode) {
        AndonDashboardDTO.QualitySummary data = andonDashboardService.getQualitySummary(productLineCode);
        return AjaxResult.success(data);
    }

    /**
     * 获取安灯事件统计
     * 
     * @param productLineCode 产线编码（可选）
     * @return 安灯事件统计
     */
    @GetMapping("/andon-events")
    public AjaxResult getAndonEventSummary(@RequestParam(required = false) String productLineCode) {
        AndonDashboardDTO.AndonEventSummary data = andonDashboardService.getAndonEventSummary(productLineCode);
        return AjaxResult.success(data);
    }
}
