package com.community.huiju.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.common.base.BaseController;
import com.community.huiju.model.TpEquipment;
import com.community.huiju.service.ITpEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 设备表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-04-15
 */
@RestController
@RequestMapping("/")
@Api(value = "设备表", description = "设备表")
public class TpEquipmentController extends BaseController {

    @Autowired
    private ITpEquipmentService iTpEquipmentService;

    @RequestMapping(value = "/equipment", method = RequestMethod.GET)
    @ApiOperation(value = "根据类型查询设备表", notes = "根据类型查询设备表")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "type", value = "1 监控 2 访客机 3 可是对讲"),
        @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    })
    public ResponseBean getAll(@RequestParam("type") Integer type, HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTpEquipmentService.getAllByCommunityAndEquipmentType(userElement, type);
        return responseBean;
    }


    @RequestMapping(value = "/equipment/monitoring", method = RequestMethod.POST)
    @ApiOperation(value = "添加或修改监控设备", notes = "添加或修改监控设备")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataTypeClass = Integer.class, name = "parameter", value = "监控设备数据"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    })
    public ResponseBean saveOrUpdateMonitoring(@RequestBody String parameter, HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTpEquipmentService.saveOrUpdateMonitoring(parameter, userElement);
        return responseBean;
    }

    @RequestMapping(value = "/equipment/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除设备", notes = "删除设备s")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "设备id"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    })
    public ResponseBean deleteEquipmentById(@PathVariable("id") Integer id, HttpSession session){
        ResponseBean responseBean = new ResponseBean();
        responseBean = iTpEquipmentService.deleteEquipmentById(id);
        return responseBean;
    }

}
