package com.yihu.wlyy.web.common.device;

import com.yihu.wlyy.entity.device.Device;
import com.yihu.wlyy.entity.device.DeviceCategory;
import com.yihu.wlyy.service.app.device.DeviceService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/common/device", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "设备管理")
public class DeviceController extends BaseController {
	
	@Autowired
	private DeviceService deviceService;



	@ApiOperation("获取设备分类")
	@RequestMapping(value = "DeviceCategory")
	@ResponseBody
	public String getDeviceCategory() {
		try {
			List<DeviceCategory> list = deviceService.findAllCategory();
			return write(200,"获取设备分类成功！","data",list);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "获取设备分类失败！");
		}
	}

	@ApiOperation("获取设备列表")
	@RequestMapping(value = "DeviceList")
	@ResponseBody
	public String getDeviceList(@ApiParam(name="category_code",value="设备类型代码",defaultValue = "1")
								 @RequestParam(value="category_code",required = true) String categoryCode) {
		try {
			List<Device> list = deviceService.findDeviceByCategory(categoryCode);
			return write(200,"获取设备列表成功！","data",list);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "获取设备列表失败！");
		}
	}

	@ApiOperation("获取设备信息")
	@RequestMapping(value = "DeviceInfo")
	@ResponseBody
	public String getDeviceInfo(@ApiParam(name="id",value="设备ID",defaultValue = "19")
									   @RequestParam(value="id",required = true) String id) {
		try {
			Device device = deviceService.findById(id);

			return write(200, "查询成功", "data", device);
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
}
