package com.xzzn.web.controller.ems;

import com.xzzn.common.core.controller.BaseController;
import com.xzzn.common.core.domain.AjaxResult;
import com.xzzn.common.enums.DeviceCategory;
import com.xzzn.ems.domain.vo.*;
import com.xzzn.ems.service.IGeneralQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 *  综合查询
 *
 */
@RestController
@RequestMapping("/ems/generalQuery")
public class EmsGeneralQueryController extends BaseController{

    @Autowired
    private IGeneralQueryService iGeneralQueryService;

    /**
     * 获取设备枚举
     */
    @GetMapping("/getAllDeviceCategory")
    public AjaxResult getDeviceCategory()
    {
        // 获取所有枚举的信息
        List<Map<String, String>> deviceCategoryList = new ArrayList<>();
        for (DeviceCategory category : DeviceCategory.values()) {
            Map<String, String> categoryMap = new HashMap<>();
            categoryMap.put("name", category.getInfo());
            categoryMap.put("code", category.getCode());
            deviceCategoryList.add(categoryMap);
        }
        return success(deviceCategoryList);
    }

    /**
     * 点位模糊查询
     */
    @PostMapping("/pointFuzzyQuery")
    public AjaxResult pointFuzzyQuery(@RequestBody PointNameRequest request)
    {
        return success(iGeneralQueryService.getPointNameList(request));
    }

    /**
     * 根据点位查询点位数据变化
     */
    @PostMapping("/getPointValueList")
    public AjaxResult getPointValueList(@RequestBody PointNameRequest request)
    {
        List<GeneralQueryResponse> result = new ArrayList<>();
        try {
            result = iGeneralQueryService.getPointValueList(request);
        } catch (Exception e) {
            logger.error("<UNK>",e);
            return error("报错请重试！");
        }
        return success(result);
    }

    /**
     * 获取设备枚举
     */
    @GetMapping("/getAllBatteryIdsBySites/{siteIds}")
    public AjaxResult getAllBatteryIdsBySites(@PathVariable String[] siteIds)
    {
        return success(iGeneralQueryService.getAllBatteryIdsBySites(siteIds));
    }
}
