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

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.gci.boot.common.log.annotation.AddSysLog;
import com.gci.boot.common.vo.Result;
import com.gci.boot.modules.dataview.service.VehiclesCenterService;
import com.gci.boot.modules.statis.service.RepairStatisService;
import com.gci.boot.modules.statis.service.UpkeepStatisService;
import com.gci.boot.modules.statis.vo.RepairBoardVO;
import com.gci.boot.modules.statis.vo.UpkeepBoardVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
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.RestController;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 数据看板-车务中心
 */
@Api(tags="数据看板-车务中心")
@Slf4j
@RestController
@RequestMapping("/dataview/vehicles")
public class VehiclesCenterController {

    @Autowired
    private UpkeepStatisService upkeepStatisService;
    @Autowired
    private RepairStatisService repairStatisService;

    @Autowired
    private VehiclesCenterService vehiclesCenterService;

    /**
     * 数据看板----维修情况
     * @param startTime
     * @param endTime
     * @return
     */
    @AddSysLog(value = "数据看板-车务中心-维修情况")
    @GetMapping(value = "/getRepairInfo")
    public Result<?> getRepairInfo(String startTime, String endTime) {
        Date startParam = null;
        Date endParam = null;
        if(StrUtil.isNotBlank(startTime)){
            startParam = DateUtil.parse(startTime);
        }
        if(StrUtil.isNotBlank(endTime)){
            endParam = DateUtil.parse(endTime);
        }

        List<RepairBoardVO> getRepairInfo = repairStatisService.getRepairInfo(startParam,endParam);
        return Result.ok(getRepairInfo);
    }

    /**
     * 数据看板----保养
     * @param startTime
     * @param endTime
     * @return
     */
    @AddSysLog(value = "数据看板-车务中心-保养")
    @GetMapping(value = "/getUpkeepInfo")
    public Result<?> getUpkeepInfo(String startTime, String endTime) {
        Date startParam = null;
        Date endParam = null;
        if(StrUtil.isNotBlank(startTime)){
            startParam = DateUtil.parse(startTime);
        }
        if(StrUtil.isNotBlank(endTime)){
            endParam = DateUtil.parse(endTime);
        }
        UpkeepBoardVO vo  = upkeepStatisService.getUpkeepInfo(startParam,endParam);
        return Result.ok(vo);
    }

    @AddSysLog(value = "数据看板-车务中心-违章统计")
    @GetMapping(value = "/violationStatistics")
    public Result<?> violationStatistics(String startTime, String endTime,Integer groupType) {
        Map resultMap = null;
        try {
            resultMap = vehiclesCenterService.violationStatistics(startTime,endTime,groupType);
        } catch (ParseException e) {
            e.printStackTrace();
            return  Result.error(e.getMessage());
        }
        return Result.ok(resultMap);
    }

    @AddSysLog(value = "数据看板-车务中心-保险统计")
    @GetMapping(value = "/insuranceStatistics")
    public Result<?> insuranceStatistics(String startTime, String endTime,Integer groupType) {
        Map resultMap = null;
        try {
            resultMap = vehiclesCenterService.insuranceStatistics(startTime,endTime,groupType);
        } catch (ParseException e) {
            e.printStackTrace();
            return  Result.error(e.getMessage());
        }
        return Result.ok(resultMap);
    }

    @AddSysLog(value = "数据看板-车务中心-事故统计")
    @GetMapping(value = "/accidentStatistics")
    public Result<?> accidentStatistics(String startTime, String endTime,Integer groupType) {
        Map resultMap = null;
        try {
            resultMap = vehiclesCenterService.accidentStatistics(startTime,endTime,groupType);
        } catch (ParseException e) {
            e.printStackTrace();
            return  Result.error(e.getMessage());
        }
        return Result.ok(resultMap);
    }


    @AddSysLog(value = "数据看板-车务中心-年检统计")
    @GetMapping(value = "/inspectionStatistics")
    public Result<?> inspectionStatistics(String startTime, String endTime,Integer groupType) {
        Map resultMap = null;
        try {
            resultMap = vehiclesCenterService.inspectionStatistics(startTime,endTime,groupType);
        } catch (ParseException e) {
            e.printStackTrace();
            return  Result.error(e.getMessage());
        }
        return Result.ok(resultMap);
    }


    @AddSysLog(value = "数据看板-车务中心-维修统计")
    @GetMapping(value = "/repairStatistics")
    public Result<?> repairStatistics(String startTime, String endTime) {
        Map resultMap = null;
        try {
            resultMap = vehiclesCenterService.repairStatistics(startTime,endTime);
        } catch (ParseException e) {
            e.printStackTrace();
            return  Result.error(e.getMessage());
        }
        return Result.ok(resultMap);
    }

    @AddSysLog(value = "数据看板-车务中心-保养统计")
    @GetMapping(value = "/upkeepStatistics")
    public Result<?> upkeepStatistics(String startTime, String endTime) {
        Map resultMap = null;
        try {
            resultMap = vehiclesCenterService.upkeepStatistics(startTime,endTime);
        } catch (ParseException e) {
            e.printStackTrace();
            return  Result.error(e.getMessage());
        }
        return Result.ok(resultMap);
    }
}
