package com.usky.fire.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.fire.domain.DemFireStatistics;
import com.usky.fire.service.DemFireStatisticsAttachService;
import com.usky.fire.service.DemFireStatisticsService;
import com.usky.fire.service.po.FireStatisticsPO;
import com.usky.fire.service.vo.DemFireStatisticsCountScattorVO;
import com.usky.fire.service.vo.DemFireStatisticsScattorVO;
import com.usky.fire.service.vo.FireBubbleVO;
import com.usky.fire.service.vo.FireLevelRatioVO;
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 java.util.Date;
import java.util.List;

/**
 * <p>
 * 消防检查人员 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-11-24
 */
@RestController
@RequestMapping("/demFireStatisticsAttach")
public class DemFireStatisticsAttachController {

    @Autowired
    private DemFireStatisticsAttachService demFireStatisticsAttachService;

    @Autowired
    private DemFireStatisticsService demFireStatisticsService;

    /**
     * 城市消防体征-火灾类型
     *
     * @return
     */
    @GetMapping("fireType")
    public ApiResult<List<String>> fireType() {
        return ApiResult.success(demFireStatisticsAttachService.getFireType());
    }

    /**
     * 城市消防体征-火灾趋势图
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param address   地址
     * @param fireType  火灾类型
     * @return
     */
    @GetMapping("fireCountByData")
    public ApiResult<List<Object>> getFireCountByData(@RequestParam(value = "startTime") String startTime,
                                                      @RequestParam(value = "endTime") String endTime,
                                                      @RequestParam(value = "address", required = false) String address,
                                                      @RequestParam(value = "fireType", required = false) String fireType) {
        return ApiResult.success(demFireStatisticsService.getFireCountByData(startTime, endTime, address, fireType));
    }


    /**
     * 火灾数据分析-火灾原因占比
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param address   火灾地址
     * @return
     */
    @GetMapping("fireCauseRatio")
    public ApiResult<List<FireLevelRatioVO>> getGroupByLevel(@RequestParam(value = "startTime", required = false) String startTime,
                                                             @RequestParam(value = "endTime", required = false) String endTime,
                                                             @RequestParam(value = "address", required = false) String address) {
        return ApiResult.success(demFireStatisticsService.getGroupByLevel(startTime, endTime, address));
    }

    /**
     * 火灾数据分析-详细火灾情况
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param address   地址
     * @param current   当前页
     * @param size      每页条数
     * @return
     */
    @GetMapping("page")
    public ApiResult<CommonPage<FireStatisticsPO>> page(@RequestParam(value = "startTime", required = false) String startTime,
                                                        @RequestParam(value = "endTime", required = false) String endTime,
                                                        @RequestParam(value = "address", required = false) String address,
                                                        @RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                                                        @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        return ApiResult.success(demFireStatisticsService.page(current, size, startTime, endTime, address));
    }

    /**
     * 火灾数据分析-详细火灾情况撒点
     *
     * @param street   街镇
     * @param lossType   伤亡类型(亡人火灾、伤人火灾)
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    @GetMapping("fireStatisticScattor")
    public ApiResult<List<DemFireStatisticsScattorVO>> fireStatisticScattor(@RequestParam(value = "street", required = false) String street,
                                                                            @RequestParam(value = "lossType", required = false) String lossType,
                                                                            @RequestParam(value = "startTime", required = false) String startTime,
                                                                            @RequestParam(value = "endTime", required = false) String endTime) {
        return ApiResult.success(demFireStatisticsService.fireStatisticScattor(street, lossType, startTime, endTime));
    }

    /**
     * 火灾数据分析-火灾情况统计
     *
     * @param street   街镇
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    @GetMapping("fireStatisticCollect")
    public ApiResult<List<DemFireStatisticsCountScattorVO>> fireStatisticCollect(@RequestParam(value = "street", required = false) String street,
                                                                                           @RequestParam(value = "startTime", required = false) String startTime,
                                                                                           @RequestParam(value = "endTime", required = false) String endTime) {
        return ApiResult.success(demFireStatisticsService.fireStatisticCollect(street, startTime, endTime));
    }

    /**
     * 火灾数据分析-火灾情况分析
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param fireType  火灾类型
     * @param unitId    单位代码
     * @return
     */
    @GetMapping("fireBubble")
    public ApiResult<List<FireBubbleVO>> getFireBubble(@RequestParam(value = "startTime", required = false) String startTime,
                                                       @RequestParam(value = "endTime", required = false) String endTime,
                                                       @RequestParam(value = "fireType", required = false) String fireType,
                                                       @RequestParam(value = "unitId", required = false) String unitId) {
        return ApiResult.success(demFireStatisticsService.getAvgAndSum(startTime, endTime, fireType, unitId));
    }
}

