lg_backend/langguanApi/Service/WasherService.cs

106 lines
3.8 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 langguanApi.Extensions;
using langguanApi.Extensions.AutoDI;
using langguanApi.Model;
using langguanApi.Model.Entity;
using Mapster;
using System.Linq.Expressions;
namespace langguanApi.Service
{
[ServiceInjection(InjectionType.Transient)]
public class WasherService : BaseService<Washer>
{
public WasherService(IConfiguration config) : base(config, nameof(Washer))
{
}
/// <summary>
/// 新增洗车机
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task addWasher(List<AddWasher> input)
{
List<Washer> result = new List<Washer>();
foreach (var item in input)
{
var entity = item.Adapt<Washer>();
result.Add(entity);
}
await base.CreateManyAsync(result);
}
/// <summary>
/// 获取洗车机列表
/// </summary>
/// <returns></returns>
public async Task<object> getWasherList()
{
Expression<Func<Washer, bool>> exp = filter => filter.IsDelete == false;
var result = (await base.GetListWithExp(exp)).OrderByDescending(p=>p.CreateDateTime).ToList();
var washerResult = new List<GetWasherDto>();//转化成需要的数据
foreach (var item in result)
{
var entity = item.Adapt<GetWasherDto>();
entity.EquipmentStatusString = item.EquipmentStatus == 0 ? "异常" : "正常";
entity.RunStatusString = item.RunStatus == 0 ? "停止" : "运行";
washerResult.Add(entity);
}
return new ApiResult()
{
code = 0,
data = new
{
total = washerResult.Count,
item = washerResult
}
};
}
/// <summary>
/// 获取洗车机历史记录(起始时间和结束时间非空根据起始时间和结束时间筛选数据如果为空默认获取30条数据)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<object> WasherHistoryList(transportReqPage input)
{
Expression<Func<Washer, bool>> exp = filter => filter.IsDelete == false;
var result = (await base.GetListWithExp(exp)).ToList();
var washerHistroyResult = new List<WasherHistoryDto>();//转化成需要的数据
foreach (var item in result)
{
var entity = item.Adapt<WasherHistoryDto>();
entity.StateString = item.State == 0 ? "停止" : "运行";
washerHistroyResult.Add(entity);
}
if (washerHistroyResult.Any())
{
if (!string.IsNullOrWhiteSpace(input.startTime))
{
washerHistroyResult = washerHistroyResult.Where(p => Convert.ToDateTime(p.Time) >= Convert.ToDateTime(input.startTime)).ToList();
}
if (!string.IsNullOrWhiteSpace(input.endTime))
{
washerHistroyResult = washerHistroyResult.Where(p => Convert.ToDateTime(p.Time) <= Convert.ToDateTime(input.endTime)).ToList();
}
if (string.IsNullOrWhiteSpace(input.startTime) && string.IsNullOrWhiteSpace(input.endTime))
{
washerHistroyResult = washerHistroyResult.OrderByDescending(p => p.Time).Take(30).ToList();
}
}
return new ApiResult()
{
code = 0,
data = new
{
total=washerHistroyResult.Count,
item= washerHistroyResult
}
};
}
}
}