设备管理
This commit is contained in:
192
DOAN.Service/MES/Device/DeviceInspectService.cs
Normal file
192
DOAN.Service/MES/Device/DeviceInspectService.cs
Normal file
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using DOAN.Model;
|
||||
|
||||
|
||||
using DOAN.Repository;
|
||||
|
||||
using System.Linq;
|
||||
using DOAN.Service.MES.dev.IService;
|
||||
using DOAN.Model.MES.dev;
|
||||
using DOAN.Model.MES.dev;
|
||||
using DOAN.Model.MES.dev.Dto;
|
||||
using DOAN.Service.MES.dev.IService;
|
||||
|
||||
namespace DOAN.Service.MES.dev
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备检查项Service业务层处理
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IDeviceInspectService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class DeviceInspectService : BaseService<DeviceInspect>, IDeviceInspectService
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询设备检查项列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<DeviceInspectDto> GetList(DeviceInspectQueryDto parm)
|
||||
{
|
||||
var predicate = Expressionable.Create<DeviceInspect>();
|
||||
|
||||
predicate.AndIF(!string.IsNullOrEmpty(parm.Name), it => it.Name.Contains(parm.Name))
|
||||
.AndIF(parm.Status >= 0, it => it.Status == parm.Status)
|
||||
.AndIF(parm.Type >= 0, it => it.Type == parm.Type)
|
||||
;
|
||||
|
||||
var response = Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.ToPage<DeviceInspect, DeviceInspectDto>(parm);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设备绑定模块 查询未绑定且状态为1 的设备检查项
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<DeviceInspectDto> GetList2(DeviceInspectQueryDto2 parm)
|
||||
{
|
||||
// 获取未绑定
|
||||
if (parm.Isbind == 0)
|
||||
{
|
||||
int[] binded = Context.Queryable<DeviceRelAccountInspect>()
|
||||
.Where(it => it.FkAccountId == parm.FkAccountId)
|
||||
|
||||
.Select(it => it.FkInspectId.Value).ToArray();
|
||||
|
||||
var exp = Expressionable.Create<DeviceInspect>()
|
||||
.AndIF(!string.IsNullOrEmpty(parm.Name),it=>it.Name.Contains(parm.Name))
|
||||
.AndIF(parm.Type > 0,it=>it.Type==parm.Type)
|
||||
.And(it=>it.Status==1);
|
||||
return Context.Queryable<DeviceInspect>()
|
||||
.Where(it => !binded.Contains(it.Id))
|
||||
.Where(exp.ToExpression())
|
||||
.ToPage<DeviceInspect, DeviceInspectDto>(parm);
|
||||
|
||||
|
||||
}
|
||||
else if (parm.Isbind == 1)
|
||||
{
|
||||
|
||||
var exp = Expressionable.Create<DeviceRelAccountInspect, DeviceInspect>()
|
||||
.AndIF(!string.IsNullOrEmpty(parm.Name), (r, i) => i.Name.Contains(parm.Name))
|
||||
.AndIF(parm.Type > 0, (r, i) => i.Type == parm.Type)
|
||||
.And((r, i) => i.Status == 1);
|
||||
// 获取绑定
|
||||
return Context.Queryable<DeviceRelAccountInspect>()
|
||||
.RightJoin<DeviceInspect>((r, i) => r.FkInspectId == i.Id)
|
||||
.Where((r, i) => r.FkAccountId == parm.FkAccountId)
|
||||
.Where(exp.ToExpression())
|
||||
.OrderBy((r, i) => r.Sort)
|
||||
.Select((r, i) => i).ToPage<DeviceInspect, DeviceInspectDto>(parm);
|
||||
}
|
||||
return null;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取详情
|
||||
/// </summary>
|
||||
/// <param name="Id"></param>
|
||||
/// <returns></returns>
|
||||
public DeviceInspect GetInfo(int Id)
|
||||
{
|
||||
var response = Queryable()
|
||||
.Where(x => x.Id == Id)
|
||||
.First();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加设备检查项
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public DeviceInspect AddDeviceInspect(DeviceInspect model)
|
||||
{
|
||||
|
||||
return Context.Insertable(model).ExecuteReturnEntity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改设备检查项
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateDeviceInspect(DeviceInspect model)
|
||||
{
|
||||
//var response = Update(w => w.Id == model.Id, it => new DeviceInspect()
|
||||
//{
|
||||
// Image = model.Image,
|
||||
// Sort = model.Sort,
|
||||
// Type = model.Type,
|
||||
// Remark = model.Remark,
|
||||
// Status = model.Status,
|
||||
// Name = model.Name,
|
||||
// CreatedBy = model.CreatedBy,
|
||||
// CreatedTime = model.CreatedTime,
|
||||
// UpdatedBy = model.UpdatedBy,
|
||||
// UpdatedTime = model.UpdatedTime,
|
||||
//});
|
||||
//return response;
|
||||
return Update(model, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加绑定关系
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public int AddBindrelative(DeviceInspectQueryDto3 parm, string name)
|
||||
{
|
||||
int result = 0;
|
||||
List<DeviceRelAccountInspect> rel_account_inspect_list = new List<DeviceRelAccountInspect>();
|
||||
|
||||
if (parm.inspect_ids != null && parm.inspect_ids.Count() > 0)
|
||||
{
|
||||
foreach (var id in parm.inspect_ids)
|
||||
{
|
||||
DeviceRelAccountInspect inspect = new DeviceRelAccountInspect();
|
||||
inspect.FkAccountId = parm.account_id;
|
||||
inspect.FkInspectId = id;
|
||||
inspect.CreatedBy = name;
|
||||
inspect.CreatedTime = DateTime.Now;
|
||||
inspect.Sort = 1;
|
||||
rel_account_inspect_list.Add(inspect);
|
||||
}
|
||||
|
||||
result = Context.Insertable(rel_account_inspect_list).ExecuteCommand();
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除绑定接口
|
||||
/// </summary>
|
||||
/// <param name="account_id"></param>
|
||||
/// <param name="inspect_id"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public int RemoveBindrelative(int account_id, int inspect_id)
|
||||
{
|
||||
return Context.Deleteable<DeviceRelAccountInspect>().Where(it => it.FkAccountId == account_id).Where(it => it.FkInspectId == inspect_id).ExecuteCommand();
|
||||
}
|
||||
|
||||
|
||||
public int SortBindrelative(List<DeviceRelAccountInspect> parm)
|
||||
{
|
||||
return Context.Updateable(parm).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user