223 lines
7.6 KiB
C#
223 lines
7.6 KiB
C#
using CronExpressionDescriptor;
|
||
using LangGuan.Command.Model;
|
||
using LangGuan.Command.Model.EntityModel;
|
||
using LangGuan.Services;
|
||
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace LangGuan.Controllers
|
||
{
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
[ApiVersion("1.0")]
|
||
[Route("api/[controller]/v{version:apiVersion}")]
|
||
[ApiController]
|
||
public class DeviceController : ControllerBase
|
||
{
|
||
private DeviceSerive _deviceSerive;
|
||
private PlanService _planService;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="deviceSerive"></param>
|
||
public DeviceController(DeviceSerive deviceSerive, PlanService planService)
|
||
{
|
||
_deviceSerive = deviceSerive;
|
||
_planService = planService;
|
||
}
|
||
/// <summary>
|
||
/// Add
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<IActionResult> Add(Device input)
|
||
{
|
||
var result = await _deviceSerive.CreateAsync(input);
|
||
return Ok(new ApiResult() { code = 0 });
|
||
}
|
||
/// <summary>
|
||
/// 删除
|
||
/// </summary>
|
||
/// <param name="ids"></param>
|
||
/// <returns></returns>
|
||
[HttpPost("remove")]
|
||
public async Task<IActionResult> remove(IEnumerable<string> ids)
|
||
{
|
||
foreach (var item in ids)
|
||
{
|
||
await _deviceSerive.RemoveAsync(item);
|
||
}
|
||
return Ok(new ApiResult() { code = 0 });
|
||
}
|
||
/// <summary>
|
||
/// 列表
|
||
/// </summary>
|
||
/// <param name="request"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("list")]
|
||
public async Task<IActionResult> list([FromQuery] RqeustPaging request)
|
||
{
|
||
var result = await _deviceSerive.GetList(request);
|
||
return Ok(result);
|
||
}
|
||
/// <summary>
|
||
/// 更新
|
||
/// </summary>
|
||
/// <param name="request"></param>
|
||
/// <returns></returns>
|
||
[HttpPost("update")]
|
||
public async Task<IActionResult> update(Device request)
|
||
{
|
||
var result = await _deviceSerive.Update(request);
|
||
return Ok(result);
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpGet("GetListByGroupState")]
|
||
public async Task<IActionResult> GetListByGroupState(bool Ingroup)
|
||
{
|
||
var result = await _deviceSerive.GetlistByGroupState(Ingroup);
|
||
return Ok(result);
|
||
}
|
||
/// <summary>
|
||
/// 设备角度调整
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
[HttpPost("SetVal")]
|
||
public async Task<IActionResult> SetVal(KeyValuePair<string, int> input)
|
||
{
|
||
return Ok(new ApiResult() { code = 0, msg = "" });
|
||
}
|
||
/// <summary>
|
||
/// 启动
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <param name="point">true,摇摆,false,定点</param>
|
||
/// <returns></returns>
|
||
[HttpGet("start")]
|
||
public async Task<IActionResult> start(string id, bool point = false)
|
||
{
|
||
var result = await _deviceSerive.startdevice(id, point);
|
||
return Ok(new ApiResult() { code = 0, msg = "", data = result });
|
||
}
|
||
[HttpGet("stop")]
|
||
public async Task<IActionResult> stop(string id)
|
||
{
|
||
var result = await _deviceSerive.stopDevice(id);
|
||
return Ok(new ApiResult() { code = 0, msg = "", data = result });
|
||
}
|
||
/// <summary>
|
||
/// 判断设备是否在计划中
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("existPlan")]
|
||
public async Task<IActionResult> existPlan(string id)
|
||
{
|
||
var result = await _planService.existsPlan(id);
|
||
return Ok(new ApiResult() { code = 0, msg = "", data = result });
|
||
}
|
||
[HttpGet("getval")]
|
||
public async Task<IActionResult> getval(string id)
|
||
{
|
||
var result = await _deviceSerive.getval(id);
|
||
return Ok(new ApiResult() { code = 0, msg = "", data = result });
|
||
}
|
||
[HttpGet("setval")]
|
||
public async Task<IActionResult> setval(string id, bool val)
|
||
{
|
||
var result = await _deviceSerive.setval(id, val);
|
||
return Ok(new ApiResult() { code = 0, msg = "" });
|
||
}
|
||
[HttpGet("readkey")]
|
||
public async Task<IActionResult> readkey(string ip, string key)
|
||
{
|
||
var result = await _deviceSerive.readkey(ip, key);
|
||
return Ok(new ApiResult() { code = 0, msg = "", data = result });
|
||
}
|
||
[HttpGet("writekey")]
|
||
public async Task<IActionResult> writekey(string ip, string key, int val)
|
||
{
|
||
await _deviceSerive.wrirekey(ip, key, val);
|
||
return Ok(new ApiResult() { code = 0, msg = "" });
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置上下俯仰,t=1上,t=2下,val=true,开始,false,停止
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <param name="t">1上,2下</param>
|
||
/// <param name="val"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("upordown")]
|
||
public async Task<IActionResult> upordown(string id, int t = 1, bool val = true)
|
||
{
|
||
await _deviceSerive.setUporDown(id, t, val);
|
||
return Ok(new ApiResult() { code = 0, msg = "" });
|
||
}
|
||
/// <summary>
|
||
/// 归零
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <param name="val"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("zero")]
|
||
public async Task<IActionResult> Zero(string id, bool val = true)
|
||
{
|
||
await _deviceSerive.Zero(id, val);
|
||
return Ok(new ApiResult() { code = 0, msg = "" });
|
||
}
|
||
/// <summary>
|
||
/// 获取上下角度
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("getupordown")]
|
||
public async Task<IActionResult> getupordown(string id)
|
||
{
|
||
var result = await _deviceSerive.GetUpOrDown(id);
|
||
return Ok(new ApiResult() { code = 0, msg = "", data = result });
|
||
}
|
||
/// <summary>
|
||
/// 左右,跟上下一样
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <param name="t"></param>
|
||
/// <param name="val"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("leftorright")]
|
||
public async Task<IActionResult> leftorright(string id, int t = 1, bool val = true)
|
||
{
|
||
await _deviceSerive.setLeftorRight(id, t, val);
|
||
return Ok(new ApiResult() { code = 0, msg = "" });
|
||
}
|
||
/// <summary>
|
||
/// 获取角度
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("getleftorright")]
|
||
public async Task<IActionResult> getleftorright(string id)
|
||
{
|
||
var result = await _deviceSerive.GetLeftOrRight(id);
|
||
return Ok(new ApiResult() { code = 0, msg = "", data = result });
|
||
}
|
||
|
||
[HttpGet("cron")]
|
||
public async Task<IActionResult> cron(string cron)
|
||
{
|
||
var result = ExpressionDescriptor.GetDescription(cron, new Options() { Locale = "zh-CN" });
|
||
return Ok(new ApiResult() { code = 0, msg = "", data = result });
|
||
}
|
||
}
|
||
}
|