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.
214 lines
7.5 KiB
214 lines
7.5 KiB
3 months ago
|
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 Kean.Infrastructure.Database.Repository.Default.Entities.Interface;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace Kean.Application.Query.Implements
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 库房查询服务实现
|
||
|
/// </summary>
|
||
|
public class WarehouseService : IWarehouseService
|
||
|
{
|
||
|
private readonly IMapper _mapper; // 模型映射
|
||
|
private readonly IDefaultDb _database; // 默认数据库
|
||
|
|
||
|
/// <summary>
|
||
|
/// 依赖注入
|
||
|
/// </summary>
|
||
|
public WarehouseService(
|
||
|
IMapper mapper,
|
||
|
IDefaultDb database)
|
||
|
{
|
||
|
_mapper = mapper;
|
||
|
_database = database;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 实现 Kean.Application.Query.Interfaces.IWarehouseService.GetWarehouseCount 方法
|
||
|
*/
|
||
|
public async Task<int> GetWarehouseCount()
|
||
|
{
|
||
|
return (await _database.From<T_WH_WAREHOUSE>()
|
||
|
.Single(w => new { Count = Function.Count(w.WAREHOUSE_ID) }))
|
||
|
.Count;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 实现 Kean.Application.Query.Interfaces.IWarehouseService.GetWarehouseList 方法
|
||
|
*/
|
||
|
public async Task<IEnumerable<Warehouse>> GetWarehouseList(string sort, int? offset, int? limit)
|
||
|
{
|
||
|
return _mapper.Map<IEnumerable<Warehouse>>(await _database.From<T_WH_WAREHOUSE>()
|
||
|
.Sort<T_WH_WAREHOUSE, Warehouse>(sort, _mapper)
|
||
|
.Page(offset, limit)
|
||
|
.Select());
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 实现 Kean.Application.Query.Interfaces.IWarehouseService.GetAreaCount 方法
|
||
|
*/
|
||
|
public async Task<int> GetAreaCount(int[] id, int? warehouse)
|
||
|
{
|
||
|
return (await GetAreaSchema(id, warehouse)
|
||
|
.Single(a => new { Count = Function.Count(a.AREA_ID) }))
|
||
|
.Count;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 实现 Kean.Application.Query.Interfaces.IWarehouseService.GetAreaList 方法
|
||
|
*/
|
||
|
public async Task<IEnumerable<Area>> GetAreaList(int[] id, int? warehouse, string sort, int? offset, int? limit)
|
||
|
{
|
||
|
return _mapper.Map<IEnumerable<Area>>(await GetAreaSchema(id, warehouse)
|
||
|
.Sort<T_WH_AREA, Area>(sort, _mapper)
|
||
|
.Page(offset, limit)
|
||
|
.Select());
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 组织 GetArea 相关方法的条件
|
||
|
*/
|
||
|
private ISchema<T_WH_AREA> GetAreaSchema(int[] id, int? warehouse)
|
||
|
{
|
||
|
var schema = _database.From<T_WH_AREA>();
|
||
|
if (id != null)
|
||
|
{
|
||
|
schema = schema.Where(a => id.Contains(a.AREA_ID));
|
||
|
}
|
||
|
if (warehouse.HasValue)
|
||
|
{
|
||
|
schema = schema.Where(a => a.WAREHOUSE_ID == warehouse);
|
||
|
}
|
||
|
return schema;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 实现 Kean.Application.Query.Interfaces.IWarehouseService.GetCellCount 方法
|
||
|
*/
|
||
|
public async Task<int> GetCellCount(int[] area, string type, bool? @in, bool? @out, string name, string state, string laneway, string cellTag)
|
||
|
{
|
||
|
return (await GetCellSchema(area, type, @in, @out, name, state, laneway, cellTag)
|
||
|
.Single(c => new { Count = Function.Count(c.CELL_ID) }))
|
||
|
.Count;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 实现 Kean.Application.Query.Interfaces.IWarehouseService.GetCellList 方法
|
||
|
*/
|
||
|
public async Task<IEnumerable<Cell>> GetCellList(int[] area, string type, bool? @in, bool? @out, string name, string state, string sort, int? offset, int? limit, string laneway, string cellTag)
|
||
|
{
|
||
|
return _mapper.Map<IEnumerable<Cell>>(await GetCellSchema(area, type, @in, @out, name, state, laneway, cellTag)
|
||
|
.Sort<V_WH_CELL, Cell>(sort, _mapper)
|
||
|
.OrderBy(r => r.CELL_ID, Infrastructure.Database.Order.Ascending)
|
||
|
.Page(offset, limit)
|
||
|
.Select());
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 组织 GetCell 相关方法的条件
|
||
|
*/
|
||
|
private ISchema<V_WH_CELL> GetCellSchema(int[] area, string type, bool? @in, bool? @out, string name, string state, string laneway, string cellTag)
|
||
|
{
|
||
|
var schema = _database.From<V_WH_CELL>().Where(c => c.CELL_FLAG == true);
|
||
|
if (area != null)
|
||
|
{
|
||
|
schema = schema.Where(c => area.Contains(c.AREA_ID));
|
||
|
}
|
||
|
if (type != null)
|
||
|
{
|
||
|
schema = schema.Where(c => c.CELL_TYPE == type);
|
||
|
}
|
||
|
if (@in.HasValue)
|
||
|
{
|
||
|
schema = schema.Where(c => c.CELL_IN == @in);
|
||
|
}
|
||
|
if (@out.HasValue)
|
||
|
{
|
||
|
schema = schema.Where(c => c.CELL_OUT == @out);
|
||
|
}
|
||
|
if (name != null)
|
||
|
{
|
||
|
schema = schema.Where(c => c.CELL_NAME == name);
|
||
|
}
|
||
|
if (state != null)
|
||
|
{
|
||
|
schema = schema.Where(c => c.RUN_STATUS == state);
|
||
|
}
|
||
|
if (cellTag != null)
|
||
|
{
|
||
|
schema = schema.Where(c => c.CELL_TAG.Contains(cellTag));
|
||
|
}
|
||
|
if (laneway != null)
|
||
|
{
|
||
|
int way = 0;
|
||
|
try
|
||
|
{
|
||
|
way = Convert.ToInt32(laneway);
|
||
|
}
|
||
|
catch { }
|
||
|
schema = schema.Where(c => c.CELL_LANEWAY == way);
|
||
|
}
|
||
|
return schema;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 实现 Kean.Application.Query.Interfaces.IWarehouseService.GetEmergencyList 方法
|
||
|
*/
|
||
|
public async Task<IEnumerable<EmergencyStation>> GetEmergencyList(string stationCode, string stationModel, string inout)
|
||
|
{
|
||
|
var schema = _database.From<IO_STATION_MODEL>()
|
||
|
.Where(r=>r.INOUT != null);
|
||
|
if (stationCode != null)
|
||
|
{
|
||
|
schema = schema.Where(r => r.STATION_CODE== stationCode);
|
||
|
}
|
||
|
if (stationModel != null)
|
||
|
{
|
||
|
schema = schema.Where(r => r.STATION_MODEL == stationModel);
|
||
|
}
|
||
|
if (inout != null)
|
||
|
{
|
||
|
schema = schema.Where(r => r.INOUT == inout);
|
||
|
}
|
||
|
return _mapper.Map<IEnumerable<EmergencyStation>>(await schema
|
||
|
.OrderBy(r=>r.STATION_CODE, Infrastructure.Database.Order.Ascending)
|
||
|
.Select());
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 实现 Kean.Application.Query.Interfaces.IWarehouseService.GetEmergencyCount 方法
|
||
|
*/
|
||
|
public async Task<int> GetEmergencyCount(string stationCode, string stationModel, string inout)
|
||
|
{
|
||
|
var schema = _database.From<IO_STATION_MODEL>()
|
||
|
.Where(r => r.INOUT != null);
|
||
|
if (stationCode != null)
|
||
|
{
|
||
|
schema = schema.Where(r => r.STATION_CODE == stationCode);
|
||
|
}
|
||
|
if (stationModel != null)
|
||
|
{
|
||
|
schema = schema.Where(r => r.STATION_MODEL == stationModel);
|
||
|
}
|
||
|
if (inout != null)
|
||
|
{
|
||
|
schema = schema.Where(r => r.INOUT == inout);
|
||
|
}
|
||
|
|
||
|
return (await schema
|
||
|
.Single(w => new { Count = Function.Count(w.STATION_CODE) }))
|
||
|
.Count;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|