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.
104 lines
4.1 KiB
104 lines
4.1 KiB
using AutoMapper;
|
|
using Kean.Application.Query.Interfaces;
|
|
using Kean.Application.Query.ViewModels;
|
|
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 WcsService : IWcsService
|
|
{
|
|
private readonly IMapper _mapper; // 模型映射
|
|
private readonly IDefaultDb _database; // 默认数据库
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public WcsService(
|
|
IMapper mapper,
|
|
IDefaultDb database)
|
|
{
|
|
_mapper = mapper;
|
|
_database = database;
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.IControlService.GetInstructionCount 方法
|
|
*/
|
|
public async Task<int> GetInstructionCount(string[] warehouse, string direction, int? function, string device, string barcode, int? state, DateTime? beginFrom, DateTime? beginTo, DateTime? endFrom, DateTime? endTo)
|
|
{
|
|
return (await GetInstructionSchema(warehouse, direction, function, device, barcode, state, beginFrom, beginTo, endFrom, endTo)
|
|
.Single(c => new { Count = Function.Count(c.CONTROL_ID) }))
|
|
.Count;
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.IControlService.GetInstructionList 方法
|
|
*/
|
|
public async Task<IEnumerable<Instruction>> GetInstructionList(string[] warehouse, string direction, int? function, string device, string barcode, int? state, DateTime? beginFrom, DateTime? beginTo, DateTime? endFrom, DateTime? endTo, string sort, int? offset, int? limit)
|
|
{
|
|
return _mapper.Map<IEnumerable<Instruction>>(await GetInstructionSchema(warehouse, direction, function, device, barcode, state, beginFrom, beginTo, endFrom, endTo)
|
|
.Sort<V_IO_CONTROL, Instruction>(sort, _mapper)
|
|
.OrderBy(c => c.BEGIN_TIME, Infrastructure.Database.Order.Descending)
|
|
.Page(offset, limit)
|
|
.Select());
|
|
}
|
|
|
|
/*
|
|
* 组织 GetInstruction 相关方法的条件
|
|
*/
|
|
private ISchema<V_IO_CONTROL> GetInstructionSchema(string[] warehouse, string direction, int? function, string device, string barcode, int? state, DateTime? beginFrom, DateTime? beginTo, DateTime? endFrom, DateTime? endTo)
|
|
{
|
|
var schema = _database.From<V_IO_CONTROL>();
|
|
if (warehouse != null)
|
|
{
|
|
schema = schema.Where(c => warehouse.Contains(c.CONTROL_WAREHOUSE));
|
|
}
|
|
if (direction != null)
|
|
{
|
|
schema = schema.Where(c => c.CONTROL_DIRECTION == direction);
|
|
}
|
|
if (function.HasValue)
|
|
{
|
|
schema = schema.Where(c => c.CONTROL_FUNCTION == function.Value);
|
|
}
|
|
if (device != null)
|
|
{
|
|
schema = schema.Where(c => c.CONTROL_DEVICE.Contains(device));
|
|
}
|
|
if (barcode != null)
|
|
{
|
|
schema = schema.Where(c => c.STOCK_BARCODE.Contains(barcode));
|
|
}
|
|
if (state.HasValue)
|
|
{
|
|
schema = schema.Where(c => c.CONTROL_STATUS == state.Value);
|
|
}
|
|
if (beginFrom.HasValue)
|
|
{
|
|
schema = schema.Where(c => c.BEGIN_TIME >= beginFrom.Value);
|
|
}
|
|
if (beginTo.HasValue)
|
|
{
|
|
schema = schema.Where(c => c.BEGIN_TIME <= beginTo.Value.AddDays(1));
|
|
}
|
|
if (endFrom.HasValue)
|
|
{
|
|
schema = schema.Where(c => c.END_TIME >= endFrom.Value);
|
|
}
|
|
if (endTo.HasValue)
|
|
{
|
|
schema = schema.Where(c => c.END_TIME <= endTo.Value.AddDays(1));
|
|
}
|
|
return schema;
|
|
}
|
|
}
|
|
}
|