/**
 * BladeX Commercial License Agreement
 * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
 * <p>
 * Use of this software is governed by the Commercial License Agreement
 * obtained after purchasing a license from BladeX.
 * <p>
 * 1. This software is for development use only under a valid license
 * from BladeX.
 * <p>
 * 2. Redistribution of this software's source code to any third party
 * without a commercial license is strictly prohibited.
 * <p>
 * 3. Licensees may copyright their own code but cannot use segments
 * from this software for such purposes. Copyright of this software
 * remains with BladeX.
 * <p>
 * Using this software signifies agreement to this License, and the software
 * must not be used for illegal purposes.
 * <p>
 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
 * not liable for any claims arising from secondary or illegal development.
 * <p>
 * Author: Chill Zhuang (bladejava@qq.com)
 */
package org.springblade.modules.nh.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.nh.excel.DeviceExcel;
import org.springblade.modules.nh.pojo.entity.DeviceEntity;
import org.springblade.modules.nh.pojo.entity.PowerStationEntity;
import org.springblade.modules.nh.pojo.vo.DeviceVO;
import org.springblade.modules.nh.service.IDeviceService;
import org.springblade.modules.nh.service.INHCommonService;
import org.springblade.modules.nh.service.IPowerStationService;
import org.springblade.modules.nh.wrapper.DeviceWrapper;
import org.springblade.modules.order.pojo.vo.OrderHomeVo;
import org.springblade.modules.order.pojo.vo.OrderStaticVo;
import org.springblade.modules.order.service.IOperationOrderService;
import org.springframework.web.bind.annotation.*;

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

/**
 * 设备管理 控制器
 *
 * @author AlexWang
 * @since 2024-05-31
 */
@RestController
@AllArgsConstructor
@RequestMapping("nh/home")
@Tag(name = "设备管理", description = "设备管理接口")
public class HomePageController extends BladeController {

	private final INHCommonService commonService;

	private final IPowerStationService stationService;

	private final BladeRedis bladeRedis;

	private final IOperationOrderService operationOrderService;

	/**
	 * 设备管理 详情
	 */
	@GetMapping("/weather")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "获取天气信息", description  = "传入电站ID")
	public R weather(Long stationId,String area,String stationCode) {
		if(stationId!=null && StringUtil.isBlank(area)){
			PowerStationEntity stationEntity = stationService.getById(stationId);
			if(stationEntity!=null){
				area = stationEntity.getCity();
			}
		}else if(StringUtil.isNotBlank(stationCode) && StringUtil.isBlank(area)){
			PowerStationEntity stationEntity = stationService.getStationDetailByPowCode(stationCode);
			if(stationEntity!=null){
				area = stationEntity.getCity();
			}
		}

		return commonService.queryWeather(area);
	}

	/**
	 * 设备管理 详情
	 */
	@GetMapping("/weatherHistory")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "获取天气历史记录", description  = "传入电站ID")
	public R weatherHistory(Long stationId,String area,String day) {
		if(stationId!=null && StringUtil.isBlank(area)){
			PowerStationEntity stationEntity = stationService.getById(stationId);
			if(stationEntity!=null){
				area = stationEntity.getCity();
			}
		}
		return commonService.queryWeatherHistory(area, day);
	}

	@GetMapping(value = "homeOrderStatic")
	@ApiOperationSupport(order = 20)
	@Operation(summary = "获取首页统计的工单已处理/未处理数据")
	public R<OrderStaticVo> homeOrderStatic(){
		OrderStaticVo staticVo=operationOrderService.homeOrderStatic();
		return R.data(staticVo);
	}


	@GetMapping(value = "pcOrderHomeIndex")
	@ApiOperationSupport(order = 25)
	@Operation(summary = "获取运维商端工单数据待接单、服务中、已完成")
	public R<OrderHomeVo> pcOrderHomeIndex(){
		OrderHomeVo staticVo=operationOrderService.pcOrderHomeIndex();
		return R.data(staticVo);
	}

}
