package com.gci.boot.modules.dataview.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gci.boot.common.log.annotation.AddSysLog;
import com.gci.boot.modules.dataview.vo.GisRoadMileVo;
import com.gci.boot.modules.gis.entity.TbGisFenceAlarm;
import com.gci.boot.modules.dataview.service.SafetyDataStatisticsService;
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;

import com.gci.boot.common.vo.Result;
import com.gci.boot.modules.dataview.service.ITbAssetCenterService;
import com.gci.boot.modules.dataview.vo.VehicleTypeVo;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  数据看板-资产中心 前端控制器
 * </p>
 *
 * @author xushuhan
 * @since 2023-09-04
 */
@RestController
@RequestMapping("/dataview/assetCenter")
public class TbAssetCenterController {

	@Autowired
	private ITbAssetCenterService tbAssetCenterService;

	@Autowired
	private SafetyDataStatisticsService safetyDataStatisticsService;

	/**
	 * 获取车辆全部资产统计
	 * @param item
	 * @return
	 */
	@AddSysLog(value = "数据看板-资产中心-获取车辆全部资产统计")
	@GetMapping("/getVehicleTotal")
	public Result<?> getVehicleTotal(VehicleTypeVo item) {
		return Result.ok(tbAssetCenterService.getVehicleTotal());
	}

	/**
	 * 获取车辆种类统计
	 * @param item
	 * @return
	 */
	@AddSysLog(value = "数据看板-资产中心-获取车辆种类统计")
	@GetMapping("/getVehicleTypeCount")
	public Result<?> getVehicleTypeCount(VehicleTypeVo item) {
		return Result.ok(tbAssetCenterService.getVehicleTypeCount(item));
	}

	/**
	 * 获取车辆种类资产统计
	 * @param item
	 * @return
	 */
	@AddSysLog(value = "数据看板-资产中心-获取车辆种类资产统计")
	@GetMapping("/getVehicleTypePrice")
	public Result<?> getVehicleTypePrice(VehicleTypeVo item) {
		return Result.ok(tbAssetCenterService.getVehicleTypeCount(new VehicleTypeVo()));
	}

	/**
	 * 车辆项目资产和数量统计
	 * @param item
	 * @return
	 */
	@AddSysLog(value = "数据看板-资产中心-车辆项目资产和数量统计")
	@GetMapping("/getVehicleProjectCount")
	public Result<?> getVehicleProjectCount(VehicleTypeVo item) {
		return Result.ok(tbAssetCenterService.getVehicleProjectCount(item));
	}

	/**
	 * 半年故障告警统计（三电）
	 * @param
	 * @return
	 */
	@AddSysLog(value = "数据看板-资产中心-半年故障告警统计（三电）")
	@GetMapping("/getFaultAlarmMonth")
	public Result<?> getFaultAlarmMonth() {
		return Result.ok(tbAssetCenterService.getFaultAlarmMonth());
	}


	/**
	 * 车辆种类能耗排名，统计近三个月的数据。
	 *
	 * @param startDate
	 * @param endDate
	 * @param req
	 * @return
	 */
	@AddSysLog(value = "数据看板-资产中心-车辆种类能耗排名，统计近三个月的数据")
	@GetMapping(value = "/energyRankByVehicle")
	public Result<?> energyRankByVehicle(String startDate, String endDate,
										 HttpServletRequest req) {
		List<GisRoadMileVo> list = tbAssetCenterService.countByTime(startDate,endDate);
		return Result.ok(list);
	}

	/**
	 * 实时未关闭车辆围栏告警统计。
	 *
	 * @param req
	 * @return
	 */
	@AddSysLog(value = "数据看板-资产中心-车辆种类能耗排名，实时未关闭车辆围栏告警统计")
	@GetMapping(value = "/fenceAlarmList")
	public Result<?> fenceAlarmList(@RequestParam(value = "startTime", required = false) String startTime,
									@RequestParam(value = "endTime", required = false) String endTime,
									@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
									@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
									HttpServletRequest req) {

		IPage<TbGisFenceAlarm> list = safetyDataStatisticsService.pageFenceList(new ArrayList<>(), null, startTime, endTime, pageNo, pageSize);
		return Result.ok(list);
	}

}
