package com.xhpc.order.controller;

import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.order.domain.XhpcInspection;
import com.xhpc.order.service.IXhpcInspectionService;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

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

@EnableScheduling
@RestController
@RequestMapping("/inspection")
@Api(value = "巡检接口", tags = "巡检接口")
public class XhpcInspectionController extends BaseController {


    @Autowired
    private IXhpcInspectionService xhpcInspectionService;


    @GetMapping("/getDataBoard")
    public AjaxResult getDataBoard(HttpServletRequest request){
        return AjaxResult.success(xhpcInspectionService.getDataBoard(request));
    }

    @GetMapping("/getRealTimeWarning")
    public AjaxResult getRealTimeWarning(){
        List<Map<String,Object>> mapList =new ArrayList<>();

//        Map<String,Object> map1 =new HashMap<>();
//        map1.put("stationName","小华充电团结平安村充电站");
//        map1.put("terminalName","4号桩B枪");
//        map1.put("time","2026-2-5 08:35:45");
//        map1.put("conent","离线时间超过2小时");
//        mapList.add(map1);
//
//        Map<String,Object> map2 =new HashMap<>();
//        map2.put("stationName","小华充电团结平安村充电站");
//        map2.put("terminalName","3号桩B枪");
//        map2.put("time","2026-2-4 08:35:45");
//        map2.put("conent","离线时间超过1小时");
//        mapList.add(map2);


        return AjaxResult.success(mapList);
    }


    @GetMapping("/getStationList")
    public AjaxResult getStationList(HttpServletRequest request) {
        //stationName：场站名称  twoDayOrder：订单量  emptyOrderRate：空订单率
        //    normal：正常  offline：离线  fault：故障 "未知": 3
        return AjaxResult.success(xhpcInspectionService.getStationList(request));
    }



    @GetMapping("/getInspectionList")
    public AjaxResult getInspectionList(@Param("stationId") Long stationId, String time) {
        //stationName：场站名称  twoDayOrder：订单量  emptyOrderRate：空订单率
        //    normal：正常  offline：离线  fault：故障 "未知": 3
        Map<String, Object> inspectionList = xhpcInspectionService.getInspectionList(stationId, time);
        return AjaxResult.success(inspectionList);
    }

    @GetMapping("/timing")
    @Scheduled(cron = "0 50 0 * * ? ")
    public void timing(){
        // 系统自动生成每日巡检项23：50
        xhpcInspectionService.timing();
    }

    @GetMapping("/getInspectionById")
    public AjaxResult getInspectionById(@Param("stationId") Long stationId,@Param("id") String id,@Param("inspectionId") Long inspectionId) {
        return xhpcInspectionService.getInspectionById(stationId, id,inspectionId);
    }

    @PostMapping("/addInspection")
    public AjaxResult addInspection(HttpServletRequest request,@RequestBody XhpcInspection xhpcInspection) {
        return xhpcInspectionService.addInspection(request,xhpcInspection);
    }


    @GetMapping("/getInspectionUserList")
    public TableDataInfo getInspectionUserList(HttpServletRequest request) {
        List<Map<String, Object>>  list = xhpcInspectionService.getInspectionUserList(request);
        return getDataTable(list);
    }


    //-------------------------------后台-----------------------------------------------
    @GetMapping("/getStationInspectionList")
    public TableDataInfo getStationInspectionList(HttpServletRequest request,String startTime,String endTime) {
        List<Map<String, Object>>  list = xhpcInspectionService.getStationInspectionList(request,startTime,endTime);
        return getDataTable(list);
    }

    @GetMapping("/getStationInspectionDateList")
    public AjaxResult getStationInspectionDateList(@Param("stationId") Long stationId, String time) {
        List<Map<String, Object>> inspectionList = xhpcInspectionService.getStationInspectionDateList(stationId, time);
        return AjaxResult.success(inspectionList);
    }

    @GetMapping("/getStationInspectionMoonList")
    public AjaxResult getStationInspectionMoonList(@Param("stationId") Long stationId, String time) {
        Map<String, Object> inspectionList = xhpcInspectionService.getStationInspectionMoonList(stationId, time);
        return AjaxResult.success(inspectionList);
    }


}
