2024-06-03 18:26:07 +08:00
|
|
|
|
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>
|
2024-06-03 19:58:08 +08:00
|
|
|
|
[AppService(ServiceType = typeof(IDeviceTaskExecuteResultService), ServiceLifetime = LifeTime.Transient)]
|
|
|
|
|
|
public class DeviceTaskExecuteResultService : BaseService<DeviceTaskExecuteResult>, IDeviceTaskExecuteResultService
|
2024-06-03 18:26:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询巡检任务结果表列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-06-03 19:58:08 +08:00
|
|
|
|
public PagedInfo<DeviceTaskExecuteResultDto> GetList(DeviceTaskExecuteResultQueryDto parm)
|
2024-06-03 18:26:07 +08:00
|
|
|
|
{
|
2024-06-03 19:58:08 +08:00
|
|
|
|
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));
|
2024-06-03 18:26:07 +08:00
|
|
|
|
|
|
|
|
|
|
var response = Queryable()
|
|
|
|
|
|
.Where(predicate.ToExpression())
|
2024-06-03 19:58:08 +08:00
|
|
|
|
.ToPage<DeviceTaskExecuteResult, DeviceTaskExecuteResultDto>(parm);
|
2024-06-03 18:26:07 +08:00
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取详情
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="Id"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-06-03 19:58:08 +08:00
|
|
|
|
public DeviceTaskExecuteResult GetInfo(string Id)
|
2024-06-03 18:26:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
var response = Queryable()
|
|
|
|
|
|
.Where(x => x.Id == Id)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加巡检任务结果表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-06-03 19:58:08 +08:00
|
|
|
|
public DeviceTaskExecuteResult AddDeviceTaskExecuteResult(DeviceTaskExecuteResult model)
|
2024-06-03 18:26:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改巡检任务结果表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-06-03 19:58:08 +08:00
|
|
|
|
public int UpdateDeviceTaskExecuteResult(DeviceTaskExecuteResult model)
|
2024-06-03 18:26:07 +08:00
|
|
|
|
{
|
2024-06-03 19:58:08 +08:00
|
|
|
|
//var response = Update(w => w.Id == model.Id, it => new DeviceTaskExecuteResult()
|
2024-06-03 18:26:07 +08:00
|
|
|
|
//{
|
|
|
|
|
|
// 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>
|
2024-06-03 19:58:08 +08:00
|
|
|
|
public bool TruncateDeviceTaskExecuteResult()
|
2024-06-03 18:26:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
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>
|
2024-06-03 19:58:08 +08:00
|
|
|
|
public (string, object, object) ImportDeviceTaskExecuteResult(List<DeviceTaskExecuteResult> list)
|
2024-06-03 18:26:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|