package com.pqs9000.controller.area;

import cn.hutool.core.collection.CollectionUtil;
import com.njcn.enums.LogTypeEnum;
import com.njcn.pojo.commons.DatePojo;
import com.njcn.pojo.commons.HttpResult;
import com.njcn.pojo.commons.runmanage.IntergralityData;
import com.njcn.utils.PubUtils;
import com.pqs9000.pojo.monitorMap.AreaMonitorBaseInfo;
import com.pqs9000.pojo.monitorMap.AreaSubLineVO;
import com.pqs9000.service.monitorMap.MonitorScopeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * system
 * 监测点区域地图
 * @author cdf
 * @date 2023/7/10
 */
@RestController
@RequestMapping("/monitorScope")
public class MonitorScopeController {

    // 日志记录
    private static final Logger logger = LoggerFactory.getLogger(MonitorScopeController.class);

    @Resource
    private MonitorScopeService monitorScopeService;


    /**
     * 监测点信息
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     */
    @GetMapping("getAreaLineMap")
    public HttpResult getAreaLineMap(@RequestParam("startTime") String startTime, @RequestParam("endTime")String endTime) {
        DatePojo datePojo;
        HttpResult result;
        datePojo = PubUtils.validateDate(startTime, endTime, "getAreaLineMap");
        if (!StringUtils.isEmpty(datePojo.getMsg())) {
            result = PubUtils.assignmentResult(null, 500, datePojo.getMsg());
            return result;
        }

        try {
            List<AreaSubLineVO> areaSubLineVOList = monitorScopeService.getMonitorScope(datePojo.getStartTime(), datePojo.getEndTime());
            if (CollectionUtil.isEmpty(areaSubLineVOList)) {
                result = PubUtils.assignmentResult(null, 500, "获取监测点信息数据为空");
            } else {
                result = PubUtils.assignmentResult(areaSubLineVOList, 200, "获取监测点信息成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("获取监测点信息数据为异常,异常为：" + e.getMessage());
            result = PubUtils.assignmentResult(null, 500, "获取监测点信息数据为异常");
        }
        return result;
    }


    /**
     * 获取指定部门监测点暂降事件个数
     * @author cdf
     * @date 2023/7/13
     */
    @GetMapping("getAreaLineEventCount")
    public HttpResult getAreaLineEventCount(@RequestParam("startTime") String startTime, @RequestParam("endTime")String endTime) {
        DatePojo datePojo;
        HttpResult result;
        datePojo = PubUtils.validateDate(startTime, endTime, "getAreaLineMap");
        if (!StringUtils.isEmpty(datePojo.getMsg())) {
            result = PubUtils.assignmentResult(null, 500, datePojo.getMsg());
            return result;
        }

        try {
            AreaMonitorBaseInfo res = monitorScopeService.getAreaLineEventCount(datePojo.getStartTime(), datePojo.getEndTime());
            if (Objects.isNull(res)) {
                result = PubUtils.assignmentResult(null, 500, "获取区域信息数据为空");
            } else {
                result = PubUtils.assignmentResult(res, 200, "获取区域信息成功");
            }
        } catch (Exception e) {
            //e.printStackTrace();
            logger.error("获取监测点信息数据为异常,异常为：" + e.getMessage());
            result = PubUtils.assignmentResult(null, 500, "获取区域信息数据为异常");
        }
        return result;
    }

}
