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.
174 lines
6.1 KiB
174 lines
6.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 Kean.Infrastructure.Utilities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Kean.Application.Query.Implements
|
|
{
|
|
/// <summary>
|
|
/// 物料信息查询服务实现
|
|
/// </summary>
|
|
public sealed class MaterialService : IMaterialService
|
|
{
|
|
private readonly IMapper _mapper; // 模型映射
|
|
private readonly IDefaultDb _database; // 默认数据库
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public MaterialService(
|
|
IMapper mapper,
|
|
IDefaultDb database)
|
|
{
|
|
_mapper = mapper;
|
|
_database = database;
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.IMaterialService.GetCategoryTree 方法
|
|
*/
|
|
public async Task<Tree<Category>> GetCategoryTree()
|
|
{
|
|
return new Tree<Category>(_mapper.Map<IEnumerable<Category>>(await _database.From<T_GOODS_CLASS>()
|
|
.Where(c => c.CLASS_FLAG == true)
|
|
.Select()), "Id", "Parent");
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.IMaterialService.GetCategorys 方法
|
|
*/
|
|
public async Task<IEnumerable<Category>> GetCategorys()
|
|
{
|
|
return _mapper.Map<IEnumerable<Category>>(await _database.From<T_GOODS_CLASS>().Select());
|
|
}
|
|
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.IMaterialService.GetMaterialItem 方法
|
|
*/
|
|
public async Task<Material> GetMaterialItem(int id)
|
|
{
|
|
return _mapper.Map<Material>(await _database.From<T_GOODS_MAIN>()
|
|
.Where(g => g.GOODS_ID == id && g.GOODS_FLAG == true)
|
|
.Single());
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.IMaterialService.GetMaterialCount 方法
|
|
*/
|
|
public async Task<int> GetMaterialCount(string code, string name, string group, int[] category)
|
|
{
|
|
return (await GetMaterialSchema(code, name, group, category)
|
|
.Single(g => new { Count = Function.Count(g.GOODS_ID) }))
|
|
.Count;
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.IMaterialService.GetMaterialList 方法
|
|
*/
|
|
public async Task<IEnumerable<Material>> GetMaterialList(string code, string name, string group, int[] category, string sort, int? offset, int? limit)
|
|
{
|
|
return _mapper.Map<IEnumerable<Material>>(await GetMaterialSchema(code, name, group, category)
|
|
.Sort<T_GOODS_MAIN, Material>(sort, _mapper)
|
|
.OrderBy(r => r.GOODS_ID, Infrastructure.Database.Order.Ascending)
|
|
.Page(offset, limit)
|
|
.Select());
|
|
}
|
|
|
|
/*
|
|
* 组织 GetMaterial 相关方法的条件
|
|
*/
|
|
private ISchema<T_GOODS_MAIN> GetMaterialSchema(string code, string name, string group, int[] category)
|
|
{
|
|
var schema = _database.From<T_GOODS_MAIN>()
|
|
.Where(g => g.GOODS_FLAG == true);
|
|
if (code != null)
|
|
{
|
|
schema = schema.Where(g => g.GOODS_CODE.Contains(code));
|
|
}
|
|
if (name != null)
|
|
{
|
|
schema = schema.Where(g => g.GOODS_NAME.Contains(name));
|
|
}
|
|
if (group != null)
|
|
{
|
|
schema = schema.Where(g => g.TYPE_ID == group);
|
|
}
|
|
if (category != null)
|
|
{
|
|
schema = schema.Where(g => category.Contains(g.CLASS_ID.Value));
|
|
}
|
|
return schema;
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.IMaterialService.GetSafetyCount 方法
|
|
*/
|
|
public async Task<int> GetSafetyCount(string code, string name, int? warehouse)
|
|
{
|
|
return (await GetSafetySchema(code, name, warehouse)
|
|
.Single(s => new { Count = Function.Count(s.SAFETY_ID) }))
|
|
.Count;
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.IMaterialService.GetSafetyList 方法
|
|
*/
|
|
public async Task<IEnumerable<Safety>> GetSafetyList(string code, string name, int? warehouse, string sort, int? offset, int? limit)
|
|
{
|
|
return _mapper.Map<IEnumerable<Safety>>(await GetSafetySchema(code, name, warehouse)
|
|
.Sort<V_GOODS_SAFETY, Safety>(sort, _mapper)
|
|
.Page(offset, limit)
|
|
.Select());
|
|
}
|
|
|
|
/*
|
|
* 组织 GetSafety 相关方法的条件
|
|
*/
|
|
private ISchema<V_GOODS_SAFETY> GetSafetySchema(string code, string name, int? warehouse)
|
|
{
|
|
var schema = _database.From<V_GOODS_SAFETY>()
|
|
.Where(s => s.GOODS_FLAG == true);
|
|
if (code != null)
|
|
{
|
|
schema = schema.Where(s => s.GOODS_CODE.Contains(code));
|
|
}
|
|
if (name != null)
|
|
{
|
|
schema = schema.Where(s => s.GOODS_NAME.Contains(name));
|
|
}
|
|
if (warehouse != null)
|
|
{
|
|
var query = _database.From<T_GOODS_SAFETY_LIST>().Where(s => s.WAREHOUSE_ID == warehouse.Value).Query(s => s.SAFETY_ID);
|
|
schema = schema.Where(s => query.Contains(s.SAFETY_ID));
|
|
}
|
|
return schema;
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Query.Interfaces.IMaterialService.GetMaterial 方法
|
|
*/
|
|
public async Task<Material> GetMaterial(string code, bool bLike)
|
|
{
|
|
var schema = _database.From<T_GOODS_MAIN>();
|
|
if (bLike)
|
|
{
|
|
schema.Where(r => r.GOODS_CODE.StartsWith(code));
|
|
}
|
|
else
|
|
{
|
|
schema.Where(r => r.GOODS_CODE == code);
|
|
}
|
|
|
|
var material = await schema.Single();
|
|
return _mapper.Map<Material>(material);
|
|
}
|
|
}
|
|
}
|