detect/detect.gui/Services/Detect/DetectTaskLogService.cs

57 lines
2.0 KiB
C#
Raw Normal View History

2024-11-14 17:11:43 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using detect.gui.Models;
using detect.gui.Models.Entities;
namespace detect.gui.Services.Detect;
public class DetectTaskLogService : ServiceBase<DetectTaskLogEntity>
{
public ApiResponse<DetectTaskLogEntity?> ListById(long id)
{
var item = Find(x => x.Id == id);
return new ApiResponse<DetectTaskLogEntity?>(0, "success", item);
}
public ApiResponse<List<DetectTaskLogEntity>?> ListAll()
{
var items = FindList(x => true, "Id", true)
.ToList();
return new ApiResponse<List<DetectTaskLogEntity>?>(0, "success", items);
}
public ApiResponse<PagedResult<DetectTaskLogEntity>> Search(long? taskId = -1, int pageNum = 1, int pageSize = 10)
{
Expression<Func<DetectTaskLogEntity,bool>> filter = x => taskId == -1 || x.TaskId == taskId;
var total = Count(filter);
var items = FindList(filter, "CreateTime", false)
.Skip((pageNum - 1) * pageSize).Take(pageSize).ToList();
var pagedResult = new PagedResult<DetectTaskLogEntity>(pageNum, pageSize, total, items);
return new ApiResponse<PagedResult<DetectTaskLogEntity>>(0, "success", pagedResult);
}
public ApiResponse<DetectTaskLogEntity?> AddData(DetectTaskLogEntity entity)
{
var data = Add(entity);
return new ApiResponse<DetectTaskLogEntity?>(0, "success", data);
}
public ApiResponse<DetectTaskLogEntity?> UpdateData(DetectTaskLogEntity entity)
{
return new ApiResponse<DetectTaskLogEntity?>(Update(entity) ? 0 : -1, "success", null);
}
public ApiResponse<DetectTaskLogEntity?> DeleteById(long id)
{
Delete(x => x.Id == id);
return new ApiResponse<DetectTaskLogEntity?>(0, "success", null);
}
public ApiResponse<DetectTaskLogEntity?> DeleteData(DetectTaskLogEntity entity)
{
Delete(entity);
return new ApiResponse<DetectTaskLogEntity?>(0, "success", null);
}
}