132 lines
4.4 KiB
C#
132 lines
4.4 KiB
C#
|
|
using System;
|
|||
|
|
using SqlSugar;
|
|||
|
|
using Infrastructure.Attribute;
|
|||
|
|
using Infrastructure.Extensions;
|
|||
|
|
using ZR.Model;
|
|||
|
|
|
|||
|
|
|
|||
|
|
using ZR.Repository;
|
|||
|
|
using ZR.Service.Dev.IDevService;
|
|||
|
|
using System.Linq;
|
|||
|
|
using ZR.Model.MES.dev;
|
|||
|
|
using ZR.Model.MES.dev.Dto;
|
|||
|
|
|
|||
|
|
namespace ZR.Service.MES.dev
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 任务执行Service业务层处理
|
|||
|
|
/// </summary>
|
|||
|
|
[AppService(ServiceType = typeof(IDeviceTaskExecuteService), ServiceLifetime = LifeTime.Transient)]
|
|||
|
|
public class DeviceTaskExecuteService : BaseService<DeviceTaskExecute>, IDeviceTaskExecuteService
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 查询任务执行列表
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="parm"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public PagedInfo<DeviceTaskExecuteDto> GetList(DeviceTaskExecuteQueryDto parm)
|
|||
|
|
{
|
|||
|
|
var predicate = Expressionable.Create<DeviceTaskExecute>();
|
|||
|
|
|
|||
|
|
var response = Queryable()
|
|||
|
|
//.OrderBy("Id asc")
|
|||
|
|
.Where(predicate.ToExpression())
|
|||
|
|
.ToPage<DeviceTaskExecute, DeviceTaskExecuteDto>(parm);
|
|||
|
|
|
|||
|
|
return response;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取详情
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="Id"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public DeviceTaskExecute GetInfo(int Id)
|
|||
|
|
{
|
|||
|
|
var response = Queryable()
|
|||
|
|
.Where(x => x.Id == Id)
|
|||
|
|
.First();
|
|||
|
|
|
|||
|
|
return response;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 添加任务执行
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="model"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public DeviceTaskExecute AddDeviceTaskExecute(DeviceTaskExecute model)
|
|||
|
|
{
|
|||
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 修改任务执行
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="model"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public int UpdateDeviceTaskExecute(DeviceTaskExecute model)
|
|||
|
|
{
|
|||
|
|
//var response = Update(w => w.Id == model.Id, it => new DeviceTaskExecute()
|
|||
|
|
//{
|
|||
|
|
// TaskName = model.TaskName,
|
|||
|
|
// Type = model.Type,
|
|||
|
|
// DistributedTime = model.DistributedTime,
|
|||
|
|
// StartTime = model.StartTime,
|
|||
|
|
// EndTime = model.EndTime,
|
|||
|
|
// Status = model.Status,
|
|||
|
|
// 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 TruncateDeviceTaskExecute()
|
|||
|
|
{
|
|||
|
|
var newTableName = $"device_task_execute_{DateTime.Now:yyyyMMdd}";
|
|||
|
|
if (Queryable().Any() && !Context.DbMaintenance.IsAnyTable(newTableName))
|
|||
|
|
{
|
|||
|
|
Context.DbMaintenance.BackupTable("device_task_execute", newTableName);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return Truncate();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 导入任务执行
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public (string, object, object) ImportDeviceTaskExecute(List<DeviceTaskExecute> list)
|
|||
|
|
{
|
|||
|
|
var x = Context.Storageable(list)
|
|||
|
|
.SplitInsert(it => !it.Any())
|
|||
|
|
.SplitError(x => x.Item.Type.IsEmpty(), "任务类型(1是巡检,2是点检)不能为空")
|
|||
|
|
//.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);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|