|
|
|
@ -3,7 +3,9 @@ using Masuit.Tools;
|
|
|
|
|
using Masuit.Tools.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
|
using PVDEMCS.Common;
|
|
|
|
|
using PVDEMCS.Common.Constant;
|
|
|
|
|
using PVDEMCS.Common.DI;
|
|
|
|
|
using PVDEMCS.Services.Models;
|
|
|
|
|
using PVDEMCS.Services.Repositories.Entities;
|
|
|
|
|
using SharpCompress.Common;
|
|
|
|
|
using System;
|
|
|
|
@ -44,9 +46,10 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.Activated == activated.Value);
|
|
|
|
|
}
|
|
|
|
|
var result = query.OrderBy(f => f.CreateAt).ToPagedList(page, size);
|
|
|
|
|
var result = query.OrderBy(f => f.DeviceCode).ToPagedList(page, size);
|
|
|
|
|
|
|
|
|
|
return new Result<PagedList<DeviceInfoEntity>>(result);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -74,7 +77,7 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.Activated == activated.Value);
|
|
|
|
|
}
|
|
|
|
|
var result = query.OrderBy(f => f.CreateAt).ToList();
|
|
|
|
|
var result = query.OrderBy(f => f.DeviceCode).ToList();
|
|
|
|
|
|
|
|
|
|
return new Result<List<DeviceInfoEntity>>(result);
|
|
|
|
|
}
|
|
|
|
@ -92,12 +95,12 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
var result = new Result<DeviceInfoEntity>();
|
|
|
|
|
|
|
|
|
|
var detail = context.DeviceInfos.Where(f => f.Id == id).FirstOrDefault();
|
|
|
|
|
if (detail == null)
|
|
|
|
|
if (detail == null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"没有找到Id:{id}的数据";
|
|
|
|
|
result.Message = $"没有找到Id:【{id}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
result.Content= detail;
|
|
|
|
|
result.Content = detail;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -116,12 +119,12 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
var query = context.DeviceInfos.Where(f => !f.IsDelete);
|
|
|
|
|
if (query.Where(f => f.DeviceName == entity.DeviceName).FirstOrDefault() != null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"已存在名称为:{entity.DeviceName}的PLC控制器";
|
|
|
|
|
result.Message = $"没有找到Id:【{entity.DeviceName}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (query.Where(f => f.DeviceCode == entity.DeviceCode).FirstOrDefault() != null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"已存在编号为:{entity.DeviceCode}的PLC控制器";
|
|
|
|
|
result.Message = $"没有找到Id:【{entity.DeviceCode}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -148,17 +151,17 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
var update = query.Where(f => f.Id == entity.Id).FirstOrDefault();
|
|
|
|
|
if (update == null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"没有找到Id:{entity.Id}的数据";
|
|
|
|
|
result.Message = $"没有找到Id:【{entity.Id}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (query.Where(f => f.DeviceName == entity.DeviceName && f.Id != entity.Id).FirstOrDefault() != null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"已存在名称为:{entity.DeviceName}的PLC控制器";
|
|
|
|
|
result.Message = $"没有找到Id:【{entity.DeviceName}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (query.Where(f => f.DeviceCode == entity.DeviceCode && f.Id != entity.Id).FirstOrDefault() != null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"已存在编号为:{entity.DeviceCode}的PLC控制器";
|
|
|
|
|
result.Message = $"没有找到Id:【{entity.DeviceCode}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -175,6 +178,7 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除PLC控制器
|
|
|
|
|
/// </summary>
|
|
|
|
@ -187,7 +191,7 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
var entity = context.DeviceInfos.Where(f => f.Id == id).FirstOrDefault();
|
|
|
|
|
if (entity == null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"没有找到Id:{id}的数据";
|
|
|
|
|
result.Message = $"没有找到Id:【{id}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -207,64 +211,105 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取PLC控制器点位分页列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="deviceId">控制器Id</param>
|
|
|
|
|
/// <param name="deviceCode">控制器编号</param>
|
|
|
|
|
/// <param name="deviceName">控制器名称</param>
|
|
|
|
|
/// <param name="equipmentName">设备名称</param>
|
|
|
|
|
/// <param name="equipmentCode">设备编号</param>
|
|
|
|
|
/// <param name="equipmentType">设备类型</param>
|
|
|
|
|
/// <param name="pointCode">点位编号</param>
|
|
|
|
|
/// <param name="pointName">点位列表</param>
|
|
|
|
|
/// <param name="page">当前页</param>
|
|
|
|
|
/// <param name="size">页大小</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Result<PagedList<DevicePointEntity>> GetDevicePointPageList(string deviceId, string pointCode, string pointName, int page, int size)
|
|
|
|
|
public Result<PagedList<DevicePoint>> GetDevicePointPageList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated, int page, int size)
|
|
|
|
|
{
|
|
|
|
|
using (var context = new EFContext())
|
|
|
|
|
{
|
|
|
|
|
var query = context.DevicePoints.Where(f => !f.IsDelete);
|
|
|
|
|
if (!deviceId.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.DeviceId == deviceId);
|
|
|
|
|
}
|
|
|
|
|
if (!pointCode.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.PointCode.StartsWith(pointCode));
|
|
|
|
|
}
|
|
|
|
|
if (!pointName.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.PointName.StartsWith(pointName));
|
|
|
|
|
}
|
|
|
|
|
var pageList = query.OrderBy(f => f.CreateAt).ToPagedList(page, size);
|
|
|
|
|
return new Result<PagedList<DevicePointEntity>>(pageList);
|
|
|
|
|
var query = DeviceQuery(deviceName, deviceCode, equipmentName, equipmentCode, equipmentType, pointCode, pointName, activated, context);
|
|
|
|
|
var pageList = query.OrderBy(f => f.PointCode).ToPagedList(page, size);
|
|
|
|
|
return new Result<PagedList<DevicePoint>>(pageList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取PLC控制器点位分页列表
|
|
|
|
|
/// 获取PLC控制器点位列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="deviceId">控制器Id</param>
|
|
|
|
|
/// <param name="deviceCode">控制器编号</param>
|
|
|
|
|
/// <param name="deviceName">控制器名称</param>
|
|
|
|
|
/// <param name="equipmentName">设备名称</param>
|
|
|
|
|
/// <param name="equipmentCode">设备编号</param>
|
|
|
|
|
/// <param name="equipmentType">设备类型</param>
|
|
|
|
|
/// <param name="pointCode">点位编号</param>
|
|
|
|
|
/// <param name="pointName">点位列表</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<DevicePointEntity> GetDevicePointList(string deviceId, string pointCode, string pointName)
|
|
|
|
|
public List<DevicePoint> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated)
|
|
|
|
|
{
|
|
|
|
|
using (var context = new EFContext())
|
|
|
|
|
{
|
|
|
|
|
var query = context.DevicePoints.Where(f => !f.IsDelete);
|
|
|
|
|
if (!deviceId.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.DeviceId == deviceId);
|
|
|
|
|
}
|
|
|
|
|
if (!pointCode.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.PointCode.StartsWith(pointCode));
|
|
|
|
|
}
|
|
|
|
|
if (!pointName.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.PointName.StartsWith(pointName));
|
|
|
|
|
}
|
|
|
|
|
var query = DeviceQuery(deviceName, deviceCode, equipmentName, equipmentCode, equipmentType, pointCode, pointName, activated, context);
|
|
|
|
|
var list = query.ToList();
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IQueryable<DevicePoint> DeviceQuery(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated, EFContext context)
|
|
|
|
|
{
|
|
|
|
|
var query = from device in context.DeviceInfos.Where(f => !f.IsDelete)
|
|
|
|
|
join point in context.DevicePoints.Where(f => !f.IsDelete) on device.Id equals point.DeviceId
|
|
|
|
|
join equipment in context.EquipmentInfos.Where(f => !f.IsDelete) on point.EquipmentId equals equipment.Id
|
|
|
|
|
select new DevicePoint
|
|
|
|
|
{
|
|
|
|
|
Id = point.Id,
|
|
|
|
|
DeviceId = device.Id,
|
|
|
|
|
DeviceCode = device.DeviceCode,
|
|
|
|
|
DeviceName = device.DeviceName,
|
|
|
|
|
EquipmentId = equipment.Id,
|
|
|
|
|
EquipmentCode = equipment.EquipmentCode,
|
|
|
|
|
EquipmentName = equipment.EquipmentName,
|
|
|
|
|
EquipmentType = equipment.EquipmentType,
|
|
|
|
|
Activated = point.Activated,
|
|
|
|
|
PointCode = point.PointCode,
|
|
|
|
|
PointName = point.PointName,
|
|
|
|
|
Address = point.Address,
|
|
|
|
|
DataType = point.DataType,
|
|
|
|
|
Remark = point.Remark,
|
|
|
|
|
};
|
|
|
|
|
if (!deviceName.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.DeviceName.StartsWith(deviceName));
|
|
|
|
|
}
|
|
|
|
|
if (!deviceCode.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.DeviceCode.StartsWith(deviceCode));
|
|
|
|
|
}
|
|
|
|
|
if (!equipmentName.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.EquipmentName.StartsWith(equipmentName));
|
|
|
|
|
}
|
|
|
|
|
if (!equipmentCode.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.EquipmentCode.StartsWith(equipmentCode));
|
|
|
|
|
}
|
|
|
|
|
if (!equipmentType.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.EquipmentType == equipmentType);
|
|
|
|
|
}
|
|
|
|
|
if (!pointCode.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.PointCode.StartsWith(pointCode));
|
|
|
|
|
}
|
|
|
|
|
if (!pointName.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.PointName.StartsWith(pointName));
|
|
|
|
|
}
|
|
|
|
|
if (activated.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(f => f.Activated == activated.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取PLC控制器点位明细
|
|
|
|
|
/// </summary>
|
|
|
|
@ -279,7 +324,7 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
var entity = context.DevicePoints.Where(f => f.Id == id).FirstOrDefault();
|
|
|
|
|
if (entity == null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"没有找到Id:{id}的数据";
|
|
|
|
|
result.Message = $"没有找到Id:【{id}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
result.Content = entity;
|
|
|
|
@ -302,12 +347,12 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
var query = context.DevicePoints.Where(f => !f.IsDelete);
|
|
|
|
|
if (query.Where(f => f.PointName == entity.PointName).FirstOrDefault() != null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"已存在名称为:{entity.PointName}的PLC控制器点位";
|
|
|
|
|
result.Message = $"没有找到Id:【{entity.PointName}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (query.Where(f => f.PointCode == entity.PointCode).FirstOrDefault() != null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"已存在编号为:{entity.PointCode}的PLC控制器点位";
|
|
|
|
|
result.Message = $"没有找到Id:【{entity.PointCode}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -325,7 +370,7 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entity"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Result UpdateDevicePoint(DevicePointEntity entity)
|
|
|
|
|
public Result UpdateDevicePoint(DevicePointEntity entity)
|
|
|
|
|
{
|
|
|
|
|
using (var context = new EFContext())
|
|
|
|
|
{
|
|
|
|
@ -335,27 +380,28 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
var update = query.Where(f => f.Id == entity.Id).FirstOrDefault();
|
|
|
|
|
if (update == null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"没有找到Id:{entity.Id}的数据";
|
|
|
|
|
result.Message = $"没有找到Id:【{entity.Id}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (query.Where(f => f.PointName == entity.PointName && f.Id != entity.Id).FirstOrDefault() != null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"已存在名称为:{entity.PointName}的PLC控制器点位";
|
|
|
|
|
result.Message = $"没有找到Id:【{entity.PointName}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (query.Where(f => f.PointCode == entity.PointCode && f.Id != entity.Id).FirstOrDefault() != null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"已存在编号为:{entity.PointCode}的PLC控制器点位";
|
|
|
|
|
result.Message = $"没有找到Id:【{entity.PointCode}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update.DeviceId = entity.DeviceId;
|
|
|
|
|
update.EquipmentId = entity.EquipmentId;
|
|
|
|
|
update.PointCode = entity.PointCode;
|
|
|
|
|
update.PointName = entity.PointName;
|
|
|
|
|
update.ActionType = entity.ActionType;
|
|
|
|
|
update.Activated = entity.Activated;
|
|
|
|
|
update.Address= entity.Address;
|
|
|
|
|
update.Type = entity.Type;
|
|
|
|
|
update.Remark= entity.Remark;
|
|
|
|
|
update.Address = entity.Address;
|
|
|
|
|
update.DataType = entity.DataType;
|
|
|
|
|
update.Remark = entity.Remark;
|
|
|
|
|
entity.Update();
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
@ -368,7 +414,7 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Result DeleteDevicePoint(string id)
|
|
|
|
|
public Result DeleteDevicePoint(string id)
|
|
|
|
|
{
|
|
|
|
|
using (var context = new EFContext())
|
|
|
|
|
{
|
|
|
|
@ -377,7 +423,7 @@ namespace PVDEMCS.Services.Repositories.Impl
|
|
|
|
|
var entity = context.DevicePoints.Where(f => f.Id == id).FirstOrDefault();
|
|
|
|
|
if (entity == null)
|
|
|
|
|
{
|
|
|
|
|
result.Message = $"没有找到Id:{id}的数据";
|
|
|
|
|
result.Message = $"没有找到Id:【{id}】的数据";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|