303 lines
11 KiB
C#
303 lines
11 KiB
C#
using System;
|
|
using SqlSugar;
|
|
using Infrastructure.Attribute;
|
|
using Infrastructure.Extensions;
|
|
using ZR.Model;
|
|
|
|
using ZR.Repository;
|
|
|
|
using System.Linq;
|
|
using ZR.Model.MES.dev;
|
|
using ZR.Model.MES.dev.Dto;
|
|
using ZR.Service.MES.dev.IService;
|
|
|
|
namespace ZR.Service.MES.dev
|
|
{
|
|
/// <summary>
|
|
/// 设备台账Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IDeviceAccountService), ServiceLifetime = LifeTime.Transient)]
|
|
public class DeviceAccountService : BaseService<DeviceAccount>, IDeviceAccountService
|
|
{
|
|
/// <summary>
|
|
/// 查询设备台账列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<DeviceAccountDto> GetList(DeviceAccountQueryDto parm)
|
|
{
|
|
// 全部设备parm.FkDeviceType == 1
|
|
// 提取parentId
|
|
DeviceType typeItem = Context.Queryable<DeviceType>()
|
|
.Where(it=>it.Id == parm.FkDeviceType)
|
|
.Where(it=>it.Status==1)
|
|
.First();
|
|
int[] typeIds = [];
|
|
// 二级菜单
|
|
if (typeItem != null && typeItem.ParentId == 1)
|
|
{
|
|
typeIds = Context.Queryable<DeviceType>()
|
|
.Where(it => it.ParentId == parm.FkDeviceType)
|
|
.Where(it => it.Status == 1)
|
|
.Select(it => it.Id)
|
|
.ToArray();
|
|
}
|
|
|
|
// 非全部设备
|
|
|
|
|
|
var predicate = Expressionable.Create<DeviceAccount>()
|
|
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), it => it.DeviceName.Contains(parm.DeviceName))
|
|
.AndIF(!string.IsNullOrEmpty(parm.DeviceSpecification), it => it.DeviceSpecification.Contains(parm.DeviceSpecification))
|
|
.AndIF(parm.Status > -1, it => it.Status == parm.Status)
|
|
.AndIF(typeItem != null && typeItem.ParentId > 1, it => it.FkDeviceType == parm.FkDeviceType)
|
|
.AndIF(typeItem != null && typeItem.ParentId == 1, it => typeIds.Contains(it.FkDeviceType))
|
|
;
|
|
|
|
var response = Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.OrderByDescending(it => it.UpdatedTime)
|
|
.OrderByDescending(it => it.CreatedTime)
|
|
.ToPage<DeviceAccount, DeviceAccountDto>(parm);
|
|
|
|
return response;
|
|
}
|
|
|
|
public PagedInfo<DeviceAccountDto> GetList_Route(DeviceAccountQueryDto2 parm)
|
|
{
|
|
var predicate = Expressionable.Create<DeviceAccount, DeviceRelRpAt>()
|
|
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), (a, r) => a.DeviceName.Contains(parm.DeviceName))
|
|
.AndIF(!string.IsNullOrEmpty(parm.DeviceSpecification), (a, r) => a.DeviceSpecification.Contains(parm.DeviceSpecification))
|
|
.And((a, r) => a.Status == 1)
|
|
.AndIF(parm.FkDeviceType > 0, (a, r) => a.FkDeviceType == parm.FkDeviceType)
|
|
.AndIF(parm.Flag == 1, (a, r) => r.FkRouteInspectionPlanId == parm.fkRouteInspectionPlanId)
|
|
.AndIF(parm.Flag == 0, (a, r) => r.FkRouteInspectionPlanId != parm.fkRouteInspectionPlanId || r.FkRouteInspectionPlanId == null)
|
|
;
|
|
|
|
|
|
var response = Context.Queryable<DeviceAccount>()
|
|
.LeftJoin<DeviceRelRpAt>((a, r) => a.Id == r.FkDeviceAccountId)
|
|
.Where(predicate.ToExpression())
|
|
.Select((a, r) => a)
|
|
.ToPage<DeviceAccount, DeviceAccountDto>(parm);
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <returns></returns>
|
|
public DeviceAccount GetInfo(int Id)
|
|
{
|
|
var response = Queryable()
|
|
.Where(x => x.Id == Id)
|
|
.First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加设备台账
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public DeviceAccount AddDeviceAccount(DeviceAccount model)
|
|
{
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改设备台账
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdateDeviceAccount(DeviceAccount model)
|
|
{
|
|
//var response = Update(w => w.Id == model.Id, it => new DeviceAccount()
|
|
//{
|
|
// FkDeviceType = model.FkDeviceType,
|
|
// DeviceName = model.DeviceName,
|
|
// DeviceCode = model.DeviceCode,
|
|
// Workshop = model.Workshop,
|
|
// Workline = model.Workline,
|
|
// Status = model.Status,
|
|
// DeviceImage = model.DeviceImage,
|
|
// DeviceFile = model.DeviceFile,
|
|
// DeviceSpecification = model.DeviceSpecification,
|
|
// ResponsiblePerson = model.ResponsiblePerson,
|
|
// Remark = model.Remark,
|
|
// CreatedBy = model.CreatedBy,
|
|
// CreatedTime = model.CreatedTime,
|
|
// UpdatedBy = model.UpdatedBy,
|
|
// UpdatedTime = model.UpdatedTime,
|
|
//});
|
|
//return response;
|
|
return Update(model, true);
|
|
}
|
|
|
|
public List<SelectTreeDto> GetSelectTree(DeviceAccountQueryDto parm)
|
|
{
|
|
try
|
|
{
|
|
var predicate = Expressionable.Create<DeviceAccount>()
|
|
.And(it => it.Status == 1);
|
|
List<SelectTreeDto> accountList = Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.OrderByDescending(it => it.UpdatedTime)
|
|
.OrderByDescending(it => it.CreatedTime)
|
|
.Select(it => new SelectTreeDto
|
|
{
|
|
Id = null,
|
|
ParentId = it.FkDeviceType.ToString(),
|
|
Label = (it.DeviceName + '-' + it.DeviceCode),
|
|
Value = it.Id.ToString()
|
|
})
|
|
.ToList();
|
|
int[] fkDeviceTypeIds = accountList.Select(it => int.Parse(it.Value)).ToArray();
|
|
List<SelectTreeDto> deviceTypeList = Context.Queryable<DeviceType>()
|
|
.Where(it => fkDeviceTypeIds.Contains(it.Id))
|
|
.Select(it => new SelectTreeDto
|
|
{
|
|
Id = it.Id.ToString(),
|
|
ParentId = it.ParentId.ToString(),
|
|
Label = it.Name,
|
|
Value = it.Name
|
|
}).ToList();
|
|
List<SelectTreeDto> list = deviceTypeList.Concat(accountList).ToList();
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加绑定关系 巡检计划和设备台账
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <param name="CreatedBy"></param>
|
|
/// <returns></returns>
|
|
public int AddRelation(DeviceAccount_routeinspect_Dto parm, string CreatedBy)
|
|
{
|
|
List<DeviceRelRpAt> DeviceRelRpAt_list = new List<DeviceRelRpAt>();
|
|
|
|
|
|
if (parm.FkDeviceAccountIdList.Length > 0)
|
|
{
|
|
foreach (var id in parm.FkDeviceAccountIdList)
|
|
{
|
|
DeviceRelRpAt rel = new DeviceRelRpAt();
|
|
rel.FkRouteInspectionPlanId = parm.FkRouteInspectionPlanId;
|
|
rel.FkDeviceAccountId = id;
|
|
rel.CreatedBy = CreatedBy;
|
|
rel.CreatedTime = DateTime.Now;
|
|
DeviceRelRpAt_list.Add(rel);
|
|
}
|
|
}
|
|
int result = Context.Insertable(DeviceRelRpAt_list).ExecuteCommand();
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 移除关系
|
|
/// </summary>
|
|
/// <param name="FkRouteInspectionPlanId"></param>
|
|
/// <param name="FkDeviceAccountId"></param>
|
|
/// <returns></returns>
|
|
public int Remove_relation(string FkRouteInspectionPlanId, int FkDeviceAccountId)
|
|
{
|
|
return Context.Deleteable<DeviceRelRpAt>()
|
|
.Where(it => it.FkRouteInspectionPlanId == FkRouteInspectionPlanId)
|
|
.Where(it => it.FkDeviceAccountId == FkDeviceAccountId)
|
|
|
|
.ExecuteCommand();
|
|
}
|
|
|
|
#region 点检和设备绑定关系
|
|
public PagedInfo<DeviceAccountDto> GetList_Point(DeviceAccountQueryDto3 parm)
|
|
{
|
|
var predicate = Expressionable.Create<DeviceAccount, DeviceRelPpAt>()
|
|
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), (a, r) => a.DeviceName.Contains(parm.DeviceName))
|
|
.AndIF(!string.IsNullOrEmpty(parm.DeviceSpecification), (a, r) => a.DeviceSpecification.Contains(parm.DeviceSpecification))
|
|
.And((a, r) => a.Status == 1)
|
|
.AndIF(parm.FkDeviceType > 0, (a, r) => a.FkDeviceType == parm.FkDeviceType)
|
|
.AndIF(parm.Flag == 1, (a, r) => r.FkPointInspectionPlanId == parm.fkPointInspectionPlanId)
|
|
.AndIF(parm.Flag == 0, (a, r) => r.FkPointInspectionPlanId != parm.fkPointInspectionPlanId || r.FkPointInspectionPlanId == null)
|
|
;
|
|
|
|
|
|
var response = Context.Queryable<DeviceAccount>()
|
|
.LeftJoin<DeviceRelPpAt>((a, r) => a.Id == r.FkDeviceAccountId)
|
|
.Where(predicate.ToExpression())
|
|
.Select((a, r) => a)
|
|
.ToPage<DeviceAccount, DeviceAccountDto>(parm);
|
|
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加绑定关系 巡检计划和设备台账
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <param name="CreatedBy"></param>
|
|
/// <returns></returns>
|
|
|
|
public int AddRelationPointAccount(DeviceAccount_pointinspect_Dto parm, string CreatedBy)
|
|
{
|
|
List<DeviceRelPpAt> DeviceRelRpAt_list = new List<DeviceRelPpAt>();
|
|
|
|
|
|
if (parm.FkDeviceAccountIdList.Length > 0)
|
|
{
|
|
foreach (var id in parm.FkDeviceAccountIdList)
|
|
{
|
|
DeviceRelPpAt rel = new DeviceRelPpAt();
|
|
rel.FkPointInspectionPlanId = parm.FkPointInspectionPlanId;
|
|
rel.FkDeviceAccountId = id;
|
|
rel.CreatedBy = CreatedBy;
|
|
rel.CreatedTime = DateTime.Now;
|
|
DeviceRelRpAt_list.Add(rel);
|
|
}
|
|
}
|
|
int result = Context.Insertable(DeviceRelRpAt_list).ExecuteCommand();
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 移除关系
|
|
/// </summary>
|
|
/// <param name="FkRouteInspectionPlanId"></param>
|
|
/// <param name="FkDeviceAccountId"></param>
|
|
/// <returns></returns>
|
|
public int RemoveRelationPointAccount(string FkPointInspectionPlanId, int FkDeviceAccountId)
|
|
{
|
|
return Context.Deleteable<DeviceRelPpAt>()
|
|
.Where(it => it.FkPointInspectionPlanId == FkPointInspectionPlanId)
|
|
.Where(it => it.FkDeviceAccountId == FkDeviceAccountId)
|
|
.ExecuteCommand();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} |