zhuangpei-mesbackend/ZR.Service/MES/dev/DeviceRouteInspectionResultService.cs
qianhao.xu 1395970ed3 提交
2024-06-03 19:58:08 +08:00

133 lines
5.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.Model;
using ZR.Model.Dto;
using ZR.Model.MES.dev;
using ZR.Model.MES.dev.Dto;
using ZR.Repository;
using ZR.Service.MES.dev.IService;
using System.Linq;
namespace ZR.Service.DeviceManagement
{
/// <summary>
/// 巡检任务结果表Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IDeviceTaskExecuteResultService), ServiceLifetime = LifeTime.Transient)]
public class DeviceTaskExecuteResultService : BaseService<DeviceTaskExecuteResult>, IDeviceTaskExecuteResultService
{
/// <summary>
/// 查询巡检任务结果表列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<DeviceTaskExecuteResultDto> GetList(DeviceTaskExecuteResultQueryDto parm)
{
var predicate = Expressionable.Create<DeviceTaskExecuteResult>()
.AndIF(!string.IsNullOrEmpty(parm.RouteInspectionPlanName), it => it.RouteInspectionPlanName.Contains(parm.RouteInspectionPlanName))
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), it => it.DeviceName.Contains(parm.DeviceName))
.AndIF(!string.IsNullOrEmpty(parm.InspectName), it => it.InspectName.Contains(parm.InspectName));
var response = Queryable()
.Where(predicate.ToExpression())
.ToPage<DeviceTaskExecuteResult, DeviceTaskExecuteResultDto>(parm);
return response;
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public DeviceTaskExecuteResult GetInfo(string Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
/// <summary>
/// 添加巡检任务结果表
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public DeviceTaskExecuteResult AddDeviceTaskExecuteResult(DeviceTaskExecuteResult model)
{
return Context.Insertable(model).ExecuteReturnEntity();
}
/// <summary>
/// 修改巡检任务结果表
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdateDeviceTaskExecuteResult(DeviceTaskExecuteResult model)
{
//var response = Update(w => w.Id == model.Id, it => new DeviceTaskExecuteResult()
//{
// Person = model.Person,
// Type = model.Type,
// ResultText = model.ResultText,
// ResultArray = model.ResultArray,
// ResultFile = model.ResultFile,
// Remark = model.Remark,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
/// <summary>
/// 清空巡检任务结果表
/// </summary>
/// <returns></returns>
public bool TruncateDeviceTaskExecuteResult()
{
var newTableName = $"device_route_inspection_result_{DateTime.Now:yyyyMMdd}";
if (Queryable().Any() && !Context.DbMaintenance.IsAnyTable(newTableName))
{
Context.DbMaintenance.BackupTable("device_route_inspection_result", newTableName);
}
return Truncate();
}
/// <summary>
/// 导入巡检任务结果表
/// </summary>
/// <returns></returns>
public (string, object, object) ImportDeviceTaskExecuteResult(List<DeviceTaskExecuteResult> list)
{
var x = Context.Storageable(list)
.SplitInsert(it => !it.Any())
.SplitError(x => x.Item.Id.IsEmpty(), "id 雪花不能为空")
.SplitError(x => x.Item.FkRouteInspectionPlanId.IsEmpty(), "巡检计划id不能为空")
//.WhereColumns(it => it.UserName)//如果不是主键可以这样实现多字段it=>new{it.x1,it.x2}
.ToStorage();
var result = x.AsInsertable.ExecuteCommand();//插入可插入部分;
string msg = $"插入{x.InsertList.Count} 更新{x.UpdateList.Count} 错误数据{x.ErrorList.Count} 不计算数据{x.IgnoreList.Count} 删除数据{x.DeleteList.Count} 总共{x.TotalList.Count}";
Console.WriteLine(msg);
//输出错误信息
foreach (var item in x.ErrorList)
{
Console.WriteLine("错误" + item.StorageMessage);
}
foreach (var item in x.IgnoreList)
{
Console.WriteLine("忽略" + item.StorageMessage);
}
return (msg, x.ErrorList, x.IgnoreList);
}
}
}