139 lines
5.9 KiB
C#
139 lines
5.9 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entitys.Entity;
|
|
using Tnb.BasicData.Entitys.Dto;
|
|
using Tnb.BasicData.Entitys;
|
|
using JNPF.Common.Const;
|
|
|
|
namespace Tnb.BasicData
|
|
{
|
|
/// <summary>
|
|
/// 物料清单
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
public class EbomService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarRepository<BasMaterial> _repository;
|
|
private readonly DataBaseManager _dbManager;
|
|
private readonly IDictionaryDataService _dictionaryDataService;
|
|
|
|
public EbomService(
|
|
ISqlSugarRepository<BasMaterial> repository,DataBaseManager dbManager,IDictionaryDataService dictionaryDataService)
|
|
{
|
|
_repository = repository;
|
|
_dbManager = dbManager;
|
|
_dictionaryDataService = dictionaryDataService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取物料清单树.
|
|
/// </summary>
|
|
/// <param name="input">获取物料清单树.</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> GetTree(EbomTreeQueryInput queryInput)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
var dic = await _dictionaryDataService.GetDicByKey(DictConst.MeasurementUnit);
|
|
|
|
// var momDbLink = await _repository.AsSugarClient().Queryable<DbLinkEntity>().FirstAsync(x => x.FullName == DbName.TNBMON);
|
|
// if (momDbLink != null)
|
|
// {
|
|
// db = _dbManager.ChangeDataBase(momDbLink);
|
|
// }
|
|
|
|
if (string.IsNullOrEmpty(queryInput.materialId))
|
|
{
|
|
var data = await db.Queryable<BasEbomD>()
|
|
.LeftJoin<BasEbomH>((a,b)=>a.ebom_id==b.id)
|
|
.LeftJoin<BasMaterial>((a,b,c)=>a.material_id==c.id)
|
|
.LeftJoin<BasEbomH>((a,b,c,d)=>a.material_id==d.material_id)
|
|
.LeftJoin<BasRoute>((a,b,c,d,e)=>d.route_id==e.id)
|
|
.LeftJoin<BasMaterial>((a,b,c,d,e,f)=>a.substitute_material_id==f.id)
|
|
.Where((a,b,c)=>a.ebom_id==queryInput.ebomId)
|
|
.Select((a,b,c,d,e,f)=>new EbomTreeOutput
|
|
{
|
|
material_id = c.name,
|
|
material_id_descrip = c.descrip,
|
|
material_id_remark = c.remark,
|
|
material_id_unit_id = c.unit_id,
|
|
feeding_control = a.feeding_control,
|
|
loss_rate = a.loss_rate,
|
|
quantity = a.quantity,
|
|
require_weight = a.require_weight,
|
|
route_name = e.Name,
|
|
version = d.version,
|
|
substitute_material_id = f.name,
|
|
hasChildren = SqlFunc.Subqueryable<BasEbomH>().Where(x=>x.material_id==a.material_id).Any(),
|
|
}).Mapper(it =>
|
|
{
|
|
it.material_id_unit_id = dic[it.material_id_unit_id].ToString();
|
|
}).ToListAsync();
|
|
return data;
|
|
}
|
|
else
|
|
{
|
|
var data = await db.Queryable<BasEbomD>()
|
|
.LeftJoin<BasEbomH>((a,b)=>a.ebom_id==b.id)
|
|
.LeftJoin<BasMaterial>((a,b,c)=>a.material_id==c.id)
|
|
.LeftJoin<BasEbomH>((a,b,c,d)=>a.material_id==d.material_id)
|
|
.LeftJoin<BasRoute>((a,b,c,d,e)=>d.route_id==e.id)
|
|
.LeftJoin<BasMaterial>((a,b,c,d,e,f)=>a.substitute_material_id==f.id)
|
|
.Where((a,b,c)=>b.material_id==queryInput.materialId && a.ebom_id==b.id)
|
|
.Select((a,b,c,d,e,f)=>new EbomTreeOutput
|
|
{
|
|
material_id = c.name,
|
|
material_id_descrip = c.descrip,
|
|
material_id_remark = c.remark,
|
|
material_id_unit_id = c.unit_id,
|
|
feeding_control = a.feeding_control,
|
|
loss_rate = a.loss_rate,
|
|
quantity = a.quantity,
|
|
require_weight = a.require_weight,
|
|
route_name = e.Name,
|
|
version = d.version,
|
|
substitute_material_id = f.name,
|
|
hasChildren = SqlFunc.Subqueryable<BasEbomH>().Where(x=>x.material_id==a.material_id).Any(),
|
|
}).Mapper(it =>
|
|
{
|
|
it.material_id_unit_id = dic[it.material_id_unit_id].ToString();
|
|
}).ToListAsync();
|
|
return data;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<Dictionary<string,string>> GetEbomVersionAndRouteName(string materialId)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
|
|
// var momDbLink = await _repository.AsSugarClient().Queryable<DbLinkEntity>().FirstAsync(x => x.FullName == DbName.TNBMON);
|
|
// if (momDbLink != null)
|
|
// {
|
|
// db = _dbManager.ChangeDataBase(momDbLink);
|
|
// }
|
|
|
|
var ebom = await db.Queryable<BasEbomH>()
|
|
.LeftJoin<BasRoute>((a,b)=>a.route_id==b.id)
|
|
.Where((a,b) => a.material_id == materialId)
|
|
.Select((a,b)=>new
|
|
{
|
|
a.version,
|
|
b.Name,
|
|
}).SingleAsync();
|
|
return new Dictionary<string,string>()
|
|
{
|
|
["version"] = ebom?.version,
|
|
["routeName"] = ebom?.Name
|
|
,
|
|
};
|
|
}
|
|
}
|
|
} |