package com.bonus.material.largeScreen.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.material.device.domain.DevInfo;
import com.bonus.material.device.domain.vo.DevInfoVo;
import com.bonus.material.largeScreen.service.ProvinceScreenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 马三炮
 * @date 2025/9/14
 */
@Slf4j
@Api(value = "网省大屏", tags = {"网省大屏"})
@RestController
@RequestMapping("/provinceScreen")
public class ProvinceScreenController extends BaseController {

    @Resource
    private ProvinceScreenService provinceScreenService;

    /**
     * 装备总量，总价值
     *
     * @return
     */
    @ApiOperation("装备总量，总价值")
    @GetMapping("/getTotalEquipment")
    public AjaxResult getTotalEquipment() {
        try {
            Map<String, Object> res = provinceScreenService.getTotalEquipment();
            return AjaxResult.success(res);
        } catch (Exception e) {
            return AjaxResult.error("装备总量，总价值异常");
        }
    }

    /**
     * 线路装备，变电装备，电缆装备
     *
     * @return
     */
    @ApiOperation("线路装备，变电装备，电缆装备")
    @GetMapping("/getEquipmentClassification")
    public AjaxResult getEquipmentClassification() {
        try {
            Map<String, Object> res = provinceScreenService.getEquipmentClassification();
            return AjaxResult.success(res);
        } catch (Exception e) {
            log.error("错误", e);
            System.err.println(e.getMessage());
            return AjaxResult.error("线路装备，变电装备，电缆装备异常");
        }
    }

    /**
     * 单位装备配置
     *
     * @return
     */
    @ApiOperation("单位装备配置")
    @GetMapping("/getUnitEquipmentConfiguration")
    public AjaxResult getUnitEquipmentConfiguration() {
        try {
            List<Map<String, Object>> res = provinceScreenService.getUnitEquipmentConfiguration();
            if (res == null) {
                logger.warn("单位装备配置数据为空");
                return AjaxResult.success(new ArrayList<>());
            }
            return AjaxResult.success(res);
        } catch (Exception e) {
            log.error("e: ", e);
            logger.error("单位装备配置异常: ", e);
            return AjaxResult.error("单位装备配置异常: " + e.getMessage());
        }
    }

    /**
     * 装备状态
     *
     * @return
     */
    @ApiOperation("装备状态")
    @GetMapping("/getEquipmentStatus")
    public AjaxResult getEquipmentStatus() {
        try {
            List<Map<String, Object>> res = provinceScreenService.getEquipmentStatus();
            return AjaxResult.success(res);
        } catch (Exception e) {
            return AjaxResult.error("装备状态异常");
        }
    }

    /**
     * 项目装备
     *
     * @return
     */
    @ApiOperation("项目装备")
    @GetMapping("/getProjectEquipment")
    public AjaxResult getProjectEquipment() {
        try {
            Map<String, Object> res = provinceScreenService.getProjectEquipment();
            return AjaxResult.success(res);
        } catch (Exception e) {
            return AjaxResult.error("项目装备异常");
        }
    }

    /**
     * 各单位装备在用率情况
     *
     * @return
     */
    @ApiOperation("各单位装备在用率情况")
    @GetMapping("/getDeptEquipment")
    public AjaxResult getDeptEquipment() {
        try {
            List<Map<String, Object>> res = provinceScreenService.getDeptEquipment();
            return AjaxResult.success(res);
        } catch (Exception e) {
            return AjaxResult.error("项目装备异常");
        }
    }

    /**
     * 工程在用装备情况
     *
     * @return
     */
    @ApiOperation("工程在用装备情况")
    @GetMapping("/getEquipmentUse")
    public AjaxResult getEquipmentUse(String proCode, String type) {
        try {
            return provinceScreenService.getEquipmentUse(proCode, type);
        } catch (Exception e) {
            return AjaxResult.error("工程在用装备情况异常");
        }
    }

    /**
     * 装备在用率统计
     *
     * @return
     */
    @ApiOperation("装备在用率统计")
    @GetMapping("/getUsageStatistics")
    public AjaxResult getUsageStatistics(Integer type) {
        try {
            List<Map<String, Object>> res = provinceScreenService.getUsageStatistics(type);
            return AjaxResult.success(res);
        } catch (Exception e) {
            return AjaxResult.error("装备在用率统计异常");
        }
    }

    /**
     * 在库装备数
     *
     * @return
     */
    @ApiOperation("在库装备数")
    @GetMapping("/getEquipmentNumber")
    public AjaxResult getEquipmentNumber() {
        try {
            List<Map<String, Object>> res = provinceScreenService.getEquipmentNumber();
            return AjaxResult.success(res);
        } catch (Exception e) {
            return AjaxResult.error("在库装备数异常");
        }
    }

    @ApiOperation(value = "收藏装备列表")
    @GetMapping("/getUsageStatisticsDetails")
    public TableDataInfo getUsageStatisticsDetails() {
        startPage();
        List<Map<String, Object>> usageStatisticsDetails = provinceScreenService.getUsageStatisticsDetails();
        return getDataTable(usageStatisticsDetails);
    }

    @ApiOperation(value = "收藏装备列表")
    @GetMapping("/getEquipmentDetails")
    public TableDataInfo getEquipmentDetails(String proName) {
        startPage();
        List<Map<String, Object>> usageStatisticsDetails = provinceScreenService.getEquipmentDetails(proName);
        return getDataTable(usageStatisticsDetails);
    }

    /**
     * 机械化率
     *
     * @return
     */
    @ApiOperation("机械化率")
    @GetMapping("/getMechanizationRate")
    public AjaxResult getMechanizationRate() {
        try {
            List<Map<String, Object>> res = provinceScreenService.getMechanizationRate();
            return AjaxResult.success(res);
        } catch (Exception e) {
            return AjaxResult.error("在库装备数异常");
        }
    }
}
