|
|
|
using Elight.Entity;
|
|
|
|
using Elight.Logic;
|
|
|
|
using Elight.Utility;
|
|
|
|
using Elight.Utility.Code;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using SqlSugar;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace _24Hour.Controllers.Common
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 设备管理
|
|
|
|
/// </summary>
|
|
|
|
[Authorize]
|
|
|
|
[ApiController]
|
|
|
|
[Route("api/Device")]
|
|
|
|
public class DeviceController : Controller
|
|
|
|
{
|
|
|
|
#region Identity
|
|
|
|
private readonly SqlSugarClient _db;//数据库
|
|
|
|
private readonly WriteSysLog _logs;//操作日志
|
|
|
|
App_Sys_UserModel _userdata = new App_Sys_UserModel();//当前用户
|
|
|
|
private readonly ILogger<LoginController> _logger;//日志
|
|
|
|
Result result = new Result();
|
|
|
|
public DeviceController(ILogger<LoginController> logger, SqlSugarClient db, WriteSysLog logs, User user)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_db = db;
|
|
|
|
_logs = logs;
|
|
|
|
_userdata = user.Userdata();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 设备管理
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取单位及单位下的设备信息
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="info"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("QueryUnitDevicelist")]
|
|
|
|
public async Task<Result> QueryUnitDevicelist()
|
|
|
|
{
|
|
|
|
var list = new List<dynamic>();
|
|
|
|
//获取设备信息
|
|
|
|
var Devicelist = await _db.Queryable<App_DeviceModel>().Where(q => q.IsDeleted == 0).ToListAsync();
|
|
|
|
//获取单位信息
|
|
|
|
var Unitlist = await _db.Queryable<App_Sys_UnitModel>().Where(q => q.IsDelete == 0).ToListAsync();
|
|
|
|
//设备通过单位Id分组循环获取单位信息及设备信息
|
|
|
|
Devicelist.GroupBy(q=>q.unitCode).ToList().ForEach(q => {
|
|
|
|
var data=Unitlist.Where(x => x.unitCode == q.Key).FirstOrDefault();
|
|
|
|
if (data!=null)
|
|
|
|
{
|
|
|
|
var state = 0;
|
|
|
|
if (q.Where(q => q.state == 0).Any())
|
|
|
|
state = 0;
|
|
|
|
else if (q.Where(q => q.state == 2).Any())
|
|
|
|
state = 2;
|
|
|
|
else if (q.Where(q => q.state == 1).Any())
|
|
|
|
state = 1;
|
|
|
|
list.Add(new
|
|
|
|
{
|
|
|
|
data.Id,
|
|
|
|
data.unitname,
|
|
|
|
data.lalon,
|
|
|
|
state,
|
|
|
|
Devicelist = q.ToList().Select(q => new { q.name, q.state, q.position })
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
result.IsSucceed = true;
|
|
|
|
result.result = list;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 根据当前登录人单位查询设备信息分页查询
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="info"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("QueryDeviceuser")]
|
|
|
|
public async Task<Result> QueryDeviceuser(App_DeviceInput Devicedata)
|
|
|
|
{
|
|
|
|
var Receptionlist = new List<App_DeviceModel>();
|
|
|
|
//查询远程会见记录
|
|
|
|
var list = await _db.Queryable<App_DeviceModel>()
|
|
|
|
.WhereIF(Devicedata.deviceno != null, q => q.deviceno.Contains(Devicedata.deviceno))
|
|
|
|
.WhereIF(Devicedata.name != null, q => q.name.Contains(Devicedata.name))
|
|
|
|
.WhereIF(Devicedata.state != null, q => q.state == Devicedata.state)
|
|
|
|
.Where(q => q.IsDeleted == 0 && q.unitCode == _userdata.unitCode).ToPageListAsync(Devicedata.PageIndex, Devicedata.PageSize);
|
|
|
|
var data = new QueryResult<App_DeviceModel>(Devicedata, list.OrderByDescending(q => q.creationtime).ToList());
|
|
|
|
result.IsSucceed = true;
|
|
|
|
result.result = data;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 设备分页查询
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="info"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("QueryDevice")]
|
|
|
|
public async Task<Result> QueryDevice(App_DeviceInput Devicedata)
|
|
|
|
{
|
|
|
|
RefAsync<int> totalNumber = 0;//总数据
|
|
|
|
var Receptionlist = new List<App_DeviceModel>();
|
|
|
|
//查询远程会见记录
|
|
|
|
var list = await _db.Queryable<App_DeviceModel>()
|
|
|
|
.WhereIF(Devicedata.deviceno != null, q => q.deviceno.Contains(Devicedata.deviceno))
|
|
|
|
.WhereIF(Devicedata.name != null, q => q.name.Contains(Devicedata.name))
|
|
|
|
.WhereIF(Devicedata.unitId != null, q => q.unitCode.Contains(Devicedata.unitId))
|
|
|
|
.WhereIF(Devicedata.state != null, q => q.state == Devicedata.state)
|
|
|
|
.Where(q => q.IsDeleted == 0).ToPageListAsync(Devicedata.PageIndex, Devicedata.PageSize, totalNumber);
|
|
|
|
Devicedata.RowsCount = totalNumber;
|
|
|
|
var data = new QueryResult<App_DeviceModel>(Devicedata, list.OrderByDescending(q => q.creationtime).ToList());
|
|
|
|
result.IsSucceed = true;
|
|
|
|
result.result = data;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 添加设备
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="info"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("AddDevice")]
|
|
|
|
public async Task<Result> AddDevice(App_DeviceModel Devicedata)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_db.BeginTran();
|
|
|
|
Devicedata.Id = Guid.NewGuid().ToString();
|
|
|
|
Devicedata.createuserId = _userdata.Id.ToString();
|
|
|
|
Devicedata.createusername = _userdata.name;
|
|
|
|
var num = await _db.Insertable(Devicedata).ExecuteCommandAsync();
|
|
|
|
_db.CommitTran();
|
|
|
|
if (num > 0)
|
|
|
|
{
|
|
|
|
result.IsSucceed = true;
|
|
|
|
result.result = "添加成功";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (System.Exception ex)
|
|
|
|
{
|
|
|
|
_db.RollbackTran();
|
|
|
|
result.IsSucceed = false;
|
|
|
|
result.Message = ex.Message;
|
|
|
|
}
|
|
|
|
_logs.WriteSysLogadd("远程会见管理", "添加远程会见", result, _db);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 修改设备
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="info"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("UpdateDevice")]
|
|
|
|
public async Task<Result> UpdateDevice(App_DeviceModel Devicedata)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_db.BeginTran();
|
|
|
|
var num = await _db.Updateable(Devicedata).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
_db.CommitTran();
|
|
|
|
if (num > 0)
|
|
|
|
{
|
|
|
|
result.IsSucceed = true;
|
|
|
|
result.result = "修改成功";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (System.Exception ex)
|
|
|
|
{
|
|
|
|
_db.RollbackTran();
|
|
|
|
result.IsSucceed = false;
|
|
|
|
result.Message = ex.Message;
|
|
|
|
}
|
|
|
|
_logs.WriteSysLogadd("远程会见管理", "修改远程会见", result, _db);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 删除设备
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="info"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("DeleteDevice")]
|
|
|
|
public async Task<Result> DeleteDevice(CurrencyDelete Currency)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_db.BeginTran();
|
|
|
|
var Receptionlist = await _db.Queryable<App_DeviceModel>().In(q => q.Id, Currency.id).ToListAsync();
|
|
|
|
Receptionlist.ForEach(q =>
|
|
|
|
{
|
|
|
|
q.IsDeleted = 1;
|
|
|
|
});
|
|
|
|
var num = await _db.Updateable(Receptionlist).ExecuteCommandAsync();
|
|
|
|
_db.CommitTran();
|
|
|
|
if (num > 0)
|
|
|
|
{
|
|
|
|
result.IsSucceed = true;
|
|
|
|
result.result = "删除成功";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (System.Exception ex)
|
|
|
|
{
|
|
|
|
_db.RollbackTran();
|
|
|
|
result.IsSucceed = false;
|
|
|
|
result.Message = ex.Message;
|
|
|
|
}
|
|
|
|
_logs.WriteSysLogadd("设备管理", "删除设备", result, _db);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|