package org.dromara.elevator.controller;

import java.util.List;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.elevator.domain.bo.ELargeScreenBo;
import org.dromara.elevator.domain.bo.ELargeScreenRepairBo;
import org.dromara.elevator.domain.bo.ELargeScreenRescueBo;
import org.dromara.elevator.domain.vo.*;
import org.dromara.elevator.service.IELargeScreenService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 监控大屏;
 *
 * @author zy
 * @date 2024-11-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/elevator/largeScreen")
public class ELargeScreenController extends BaseController {

    private final IELargeScreenService eLargeScreenService;

    /**
     * 查询监控大屏;列表
     */
    @SaCheckPermission("elevator:largeScreen:list")
    @GetMapping("/list")
    public TableDataInfo<ELargeScreenVo> list(ELargeScreenBo bo, PageQuery pageQuery) {
        return eLargeScreenService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出监控大屏;列表
     */
    @SaCheckPermission("elevator:largeScreen:export")
    @Log(title = "监控大屏;", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ELargeScreenBo bo, HttpServletResponse response) {
        List<ELargeScreenVo> list = eLargeScreenService.queryList(bo);
        ExcelUtil.exportExcel(list, "监控大屏;", ELargeScreenVo.class, response);
    }

    /**
     * 获取监控大屏;详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/{id}")
    public R<ELargeScreenVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(eLargeScreenService.queryById(id));
    }

    /**
     * 新增监控大屏;
     */
    @SaCheckPermission("elevator:largeScreen:add")
    @Log(title = "监控大屏;", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ELargeScreenBo bo) {
        return toAjax(eLargeScreenService.insertByBo(bo));
    }

    /**
     * 修改监控大屏;
     */
    @SaCheckPermission("elevator:largeScreen:edit")
    @Log(title = "监控大屏;", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ELargeScreenBo bo) {
        return toAjax(eLargeScreenService.updateByBo(bo));
    }

    /**
     * 删除监控大屏;
     *
     * @param ids 主键串
     */
    @SaCheckPermission("elevator:largeScreen:remove")
    @Log(title = "监控大屏;", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(eLargeScreenService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 大屏电梯总数统计
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/quantity/statistics")
    public R<ElevatorQuantityStatisticsVo> queryElevatorQuantityStatistics() {
        return R.ok(eLargeScreenService.queryElevatorQuantityStatistics());
    }

    /**
     * 大屏(首页)维保数量统计
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/maintenance/quantity/statistics")
    public R<ElevatorMaintenanceStatisticsVo> queryMaintenanceStatistics() {
        return R.ok(eLargeScreenService.queryMaintenanceStatistics());
    }

    /**
     * 大屏电梯统计
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/elevator/statistics")
    public R<ELargeScreenElevatorVo> queryElevatorStatistics() {
        return R.ok(eLargeScreenService.queryElevatorStatistics());
    }

    /**
     * 大屏(保养页)维保统计
     *
     * @param maintenanceName 维保单位名称
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/maintenance/task/statistics")
    public R<ELargeScreenMaintenanceVo> queryMaintenanceTaskStatistics(String maintenanceName) {
        return R.ok(eLargeScreenService.queryMaintenanceTaskStatistics(maintenanceName));
    }

    /**
     * 大屏(维修页)趋势图
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/repair/trend/chart")
    public R<List<ELargeScreenRepairTrendChartVo>> queryRepairTrendChart() {
        return R.ok(eLargeScreenService.queryRepairTrendChart());
    }

    /**
     * 大屏(维修页)饼图
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/repair/pie/chart")
    public R<List<ELargeScreenRepairPieChartVo>> queryRepairPieChart(ELargeScreenRepairBo bo) {
        return R.ok(eLargeScreenService.queryRepairPieChart(bo));
    }

    /**
     * 大屏(维修页)柱状图
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/repair/bar/chart")
    public R<List<ELargeScreenRepairBarChartVo>> queryRepairBarChart(ELargeScreenRepairBo bo) {
        return R.ok(eLargeScreenService.queryRepairBarChart(bo));
    }

    /**
     * 大屏电梯详情
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/detail/{elevatorNum}")
    public R<ELargeScreenElevatorInfoVo> queryElevatorDetail(@PathVariable String elevatorNum) {
        return R.ok(eLargeScreenService.queryElevatorDetail(elevatorNum));
    }

    /**
     * 大屏电梯详情-历史故障
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/detail/faultStatistics/{elevatorNum}")
    public R<List<ELargeScreenDetailFaultStatisticsVo>> queryElevatorDetailFaultStatistics(@PathVariable String elevatorNum) {
        return R.ok(eLargeScreenService.queryElevatorDetailFaultStatistics(elevatorNum));
    }

    /**
     * 救援-年度数据统计
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/rescue/year/statistics")
    public R<List<ELargeScreenRescueStatisticsVo>> queryRescueYearStatistics() {
        return R.ok(eLargeScreenService.queryRescueYearStatistics());
    }

    /**
     * 救援-各区域救援次数统计
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/rescue/area/statistics")
    public R<List<ELargeScreenRescueAreaStatisticsVo>> queryRescueAreaStatistics(ELargeScreenRescueBo bo) {
        return R.ok(eLargeScreenService.queryRescueAreaStatistics(bo));
    }

    /**
     * 救援-时间占比统计
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/rescue/time/statistics")
    public R<ELargeScreenRescueTimeStatisticsVo> queryRescueTimeStatistics(ELargeScreenRescueBo bo) {
        return R.ok(eLargeScreenService.queryRescueTimeStatistics(bo));
    }

    /**
     * 救援-故障原因统计
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/rescue/faultCause/statistics")
    public R<List<ELargeScreenRescueFaultStatisticsVo>> queryRescueFaultCauseStatistics(ELargeScreenRescueBo bo) {
        return R.ok(eLargeScreenService.queryRescueFaultCauseStatistics(bo));
    }

    /**
     * 救援-维保救援时间排名
     */
    @SaCheckPermission("elevator:largeScreen:query")
    @GetMapping("/rescue/maintenance/rank/statistics")
    public R<List<ELargeScreenRescueRankStatisticsVo>> queryRescueMaintenanceRankStatistics(ELargeScreenRescueBo bo) {
        return R.ok(eLargeScreenService.queryRescueMaintenanceRankStatistics(bo));
    }
}
