package com.casic.missiles.modular.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.casic.missiles.core.application.context.AbstractPermissionContext;
import com.casic.missiles.core.base.controller.BaseController;
import com.casic.missiles.core.datascope.DataScope;
import com.casic.missiles.core.page.PageFactory;
import com.casic.missiles.modular.system.service.DeviceTubeService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author  cz
 * @date   2022-07-06
 */
@RestController
@RequestMapping("/tube")
public class DeviceTubeController extends BaseController {

    private final DeviceTubeService tubeService;
    private AbstractPermissionContext permissionService;

    public DeviceTubeController(DeviceTubeService tubeService,  AbstractPermissionContext permissionService) {
        this.tubeService = tubeService;
        this.permissionService = permissionService;
    }

    /**
     * 获取点位列表
     */
    @RequestMapping(value = "/well/list")
    @ResponseBody
    public Object tubeDeviceList() {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        return tubeService.deviceList(dataScope);
    }

    /**
     * 获取管盯设备组列表信息
     */
    @RequestMapping(value = "/groups/list")
    @ResponseBody
    public Object DevicesGroupList() {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        return tubeService.deviceGroupsList(dataScope);
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/groupdevice/listpage")
    @ResponseBody
    public Object DeviceListPage(String wellGroupId, Integer order) {
        Page<Map<String, Object>> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        return tubeService.groupDeviceListPage(order,page, wellGroupId, dataScope);
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/groupdevice/history")
    @ResponseBody
    public Object DeviceHistory(String devcode, String beginTime, String endTime) {
        Page<Map<String, Object>> page = PageFactory.defaultPage();
        return tubeService.tubeDataHistory(page,devcode, beginTime,  endTime);
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/groupdevice/list")
    @ResponseBody
    public Object DeviceList(String wellGroupId) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        return tubeService.groupDeviceList(wellGroupId, dataScope);
    }


    /**
     * 获取详情信息
     */
    @RequestMapping(value = "/detail/{detailId}")
    @ResponseBody
    public Object list(@PathVariable(name = "detailId") String tubeId) {
        return tubeService.deviceDetail(tubeId);
    }
}
