You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.9 KiB
122 lines
3.9 KiB
using AutoMapper;
|
|
using Kean.Application.Query.Interfaces;
|
|
using Kean.Infrastructure.Database;
|
|
using Kean.Infrastructure.Database.Repository.Default;
|
|
using Kean.Infrastructure.Database.Repository.Default.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Kean.Application.Query.Implements
|
|
{
|
|
/// <summary>
|
|
/// 任务信息查询服务实现
|
|
/// </summary>
|
|
public sealed class TaskService : ITaskService
|
|
{
|
|
private readonly IMapper _mapper; // 模型映射
|
|
private readonly IDefaultDb _database; // 默认数据库
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public TaskService(
|
|
IMapper mapper,
|
|
IDefaultDb database)
|
|
{
|
|
_mapper = mapper;
|
|
_database = database;
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.ITaskService.GetTaskCount 方法
|
|
*/
|
|
public async Task<int> GetTaskCount(
|
|
int[] area,
|
|
string type,
|
|
string qualityState,
|
|
string barcode,
|
|
string original,
|
|
string destination,
|
|
DateTime? timeFrom,
|
|
DateTime? timeTo)
|
|
{
|
|
return (await GetTaskSchema(area, type, qualityState, barcode, original, destination, timeFrom, timeTo)
|
|
.Single(m => new { Count = Function.Count(m.MANAGE_ID) }))
|
|
.Count;
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.ITaskService.GetTaskList 方法
|
|
*/
|
|
public async Task<IEnumerable<ViewModels.Task>> GetTaskList(
|
|
int[] area,
|
|
string type,
|
|
string qualityState,
|
|
string barcode,
|
|
string original,
|
|
string destination,
|
|
DateTime? timeFrom,
|
|
DateTime? timeTo,
|
|
string sort,
|
|
int? offset,
|
|
int? limit)
|
|
{
|
|
return _mapper.Map<IEnumerable<ViewModels.Task>>(await GetTaskSchema(area, type, qualityState, barcode, original, destination, timeFrom, timeTo)
|
|
.Sort<V_MANAGE_MAIN, ViewModels.Task>(sort, _mapper)
|
|
.OrderBy(r => r.MANAGE_ID, Infrastructure.Database.Order.Ascending)
|
|
.Page(offset, limit)
|
|
.Select());
|
|
}
|
|
|
|
/*
|
|
* 组织 GetTask 相关方法的条件
|
|
*/
|
|
private ISchema<V_MANAGE_MAIN> GetTaskSchema(
|
|
int[] area,
|
|
string type,
|
|
string qualityState,
|
|
string barcode,
|
|
string original,
|
|
string destination,
|
|
DateTime? timeFrom,
|
|
DateTime? timeTo)
|
|
{
|
|
var schema = _database.From<V_MANAGE_MAIN>();
|
|
if (area != null)
|
|
{
|
|
schema = schema.Where(m => (area.Contains(m.START_AREA_ID) || area.Contains(m.END_AREA_ID)));
|
|
}
|
|
if (type != null)
|
|
{
|
|
schema = schema.Where(m => m.MANAGE_TYPE == type);
|
|
}
|
|
if (barcode != null)
|
|
{
|
|
schema = schema.Where(m => m.STOCK_BARCODE.Contains(barcode));
|
|
}
|
|
if (original != null)
|
|
{
|
|
schema = schema.Where(m => m.START_CELL_NAME.Contains(original));
|
|
}
|
|
if (destination != null)
|
|
{
|
|
schema = schema.Where(m => m.END_CELL_NAME.Contains(destination));
|
|
}
|
|
if (timeFrom.HasValue)
|
|
{
|
|
schema = schema.Where(m => m.BEGIN_TIME >= timeFrom.Value);
|
|
}
|
|
if (timeTo.HasValue)
|
|
{
|
|
schema = schema.Where(m => m.BEGIN_TIME <= timeTo.Value.AddDays(1));
|
|
}
|
|
if (qualityState != null)
|
|
{
|
|
schema = schema.Where(m => m.GOODS_QC_STATE == qualityState);
|
|
}
|
|
return schema;
|
|
}
|
|
}
|
|
}
|