package cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory.vo.*;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factoryinfo.FactoryInfoDO;
import cn.iocoder.yudao.module.smartfactory.service.factoryinfo.FactoryInfoService;
import cn.iocoder.yudao.module.smartfactory.service.screendata.ScreenDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
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 javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

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

@Tag(name = "工厂大屏数据")
@RestController
@RequestMapping("/smartfactory/factory-screen-data")
@Validated
public class FactoryScreenDataController {

    @Resource
    private ScreenDataService screenDataService;
    @Resource
    private FactoryInfoService factoryInfoService;

    /**
     * @param code
     * @return
     */
    @GetMapping("/getProvincesData")
    @Operation(summary = "大屏全局省份/省/市工厂数据(包函工厂基本信息)")
    @PermitAll
    public CommonResult<List<ProvincesDataRespVO>> getProvincesData(@RequestParam(required = false) String code) {
        List<ProvincesDataRespVO> provincesDataList = screenDataService.getProvincesData(code);
        return success(provincesDataList);
    }

    @GetMapping("/getStaffData")
    @Operation(summary = "大屏员工信息数据")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    @PermitAll
    public CommonResult<StaffDataRespVO> getStaffData(@RequestParam Long factoryId) {
        StaffDataRespVO staffDataRespVO = screenDataService.getStaffData(factoryId);
        return success(staffDataRespVO);
    }

    @GetMapping("/getPropertyData")
    @Operation(summary = "大屏资产数据")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    @PermitAll
    public CommonResult<PropertyDataRespVO> getPropertyData(@RequestParam Long factoryId) {
        PropertyDataRespVO propertyDataRespVO = screenDataService.getPropertyData(factoryId);
        return success(propertyDataRespVO);
    }

    @GetMapping("/getFactoryOperateData")
    @Operation(summary = "大屏工厂运营数据 调用接口 http://znkj.ispt.com.cn/prod-api/screen/detail/dateList?factoryId=10000011")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    @PermitAll
    public CommonResult<OperateDataRespVO> getFactoryOperateData(@RequestParam Long factoryId) {
        OperateDataRespVO factoryOperateDataRespVO = screenDataService.getFactoryOperateData(factoryId);
        return success(factoryOperateDataRespVO);
    }

    @GetMapping("/getFactoryRollData")
    @Operation(summary = "大屏工厂滚动数据")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    @PermitAll
    public CommonResult<List<FactoryRollDataRespVO>> getFactoryRollData() {
        List<FactoryRollDataRespVO> list = screenDataService.getFactoryRollData();
        return success(list);
    }

    @GetMapping("/getFactoryCamerasData")
    @Operation(summary = "大屏工厂监控视频数据")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    @PermitAll
    public CommonResult<List<FactoryCameraDataRespVO>> getFactoryCamerasData(@RequestParam Long factoryId) {
        List<FactoryCameraDataRespVO> factoryCameraDatas = screenDataService.getFactoryCamerasData(factoryId);
        return success(factoryCameraDatas);
    }

    @GetMapping("/getFactoryWeatherInfo")
    @Operation(summary = "大屏工厂天气数据")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    @PermitAll
    public CommonResult<FactoryWeatherDataRespVO> getFactoryWeatherInfo(@RequestParam Long factoryId) {
        return success(screenDataService.getFactoryWeatherInfo(factoryId));
    }

    /**
     * 大屏工厂打包线数据
     *
     * @param factoryId
     * @return
     */
    @GetMapping("/getFactoryPackLineInfo")
    @Operation(summary = "大屏工厂打包线数据")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    @PermitAll
    public CommonResult<List<FactoryPackLineInfoVO>> getFactoryPackLineInfo(@RequestParam Long factoryId) {
        return success(screenDataService.getFactoryPackLineInfo(factoryId));
    }


    /**
     * @param code
     * @return
     */
    @GetMapping("/getAliYunGeo")
    @Operation(summary = "获取阿里云地址")
    @PermitAll
    public CommonResult<String> getAliYunGeo(@RequestParam String code, @RequestParam Integer type) {
        String data = screenDataService.getAliYunGeo(code, type);
        return success(data);
    }


    @GetMapping("/getDataOverview")
    @Operation(summary = "获取大屏数据总览")
    @PermitAll
    public CommonResult<DataOverviewVO> getDataOverview() {
        DataOverviewVO data = screenDataService.getDataOverview();
        return success(data);
    }

    @GetMapping("/getInboundAndOutboundOverview")
    @Operation(summary = "获取大屏出入库top5")
    @PermitAll
    public CommonResult<List<InboundAndOutboundOverviewVO>> getInboundAndOutboundOverview() {
        List<InboundAndOutboundOverviewVO> data = screenDataService.getInboundAndOutboundOverview();
        return success(data);
    }

    @GetMapping("/excellentRateRanking")
    @Operation(summary = "优等率排行")
    @PermitAll
    public CommonResult<List<ExcellentRateRankingVO>> excellentRateRanking() {
        List<ExcellentRateRankingVO> data = screenDataService.excellentRateRanking();
        return success(data);
    }


    @GetMapping("/energyConservation")
    @Operation(summary = "节能减排")
    @PermitAll
    public CommonResult<List<EnergyConservationVO>> energyConservation(@RequestParam(required = false) Long factoryId) {
        List<EnergyConservationVO> data = screenDataService.energyConservation(factoryId);
        return success(data);
    }


    @GetMapping("/getObtainFactoryInboundAndOutboundStatus")
    @Operation(summary = "获取工厂出入库情况")
    @PermitAll
    public CommonResult<ObtainFactoryInboundAndOutboundStatusVO> getObtainFactoryInboundAndOutboundStatus(@RequestParam Long factoryId) {
        ObtainFactoryInboundAndOutboundStatusVO data = screenDataService.getObtainFactoryInboundAndOutboundStatus(factoryId);
        return success(data);
    }

    @GetMapping("/getFactoryInfoById")
    @Operation(summary = "获取工厂详情")
    @PermitAll
    public CommonResult<FactoryInfoDO> getFactoryInfoById(@RequestParam Long factoryId) {
        FactoryInfoDO sfFactoryInfo = factoryInfoService.getFactoryInfo(factoryId);
        return success(sfFactoryInfo);
    }

}