192 lines
8.4 KiB
C#
192 lines
8.4 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Systems.Entitys.Permission;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.BasicData.Entities.Dto;
|
|
using Tnb.BasicData.Entitys.Dto.BasProcess;
|
|
using Tnb.BasicData.Interfaces;
|
|
|
|
namespace Tnb.BasicData
|
|
{
|
|
/// <summary>
|
|
/// 物料清单
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
[OverideVisualDev(ModelId)]
|
|
public class BasEbomService : IBasEbomService,IOverideVisualDevService,IDynamicApiController, ITransient
|
|
{
|
|
public const string ModelId = "25487105536805";
|
|
private readonly ISqlSugarRepository<BasMaterial> _repository;
|
|
private readonly DataBaseManager _dbManager;
|
|
private readonly IDictionaryDataService _dictionaryDataService;
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
|
|
public BasEbomService(
|
|
ISqlSugarRepository<BasMaterial> repository,DataBaseManager dbManager,IDictionaryDataService dictionaryDataService)
|
|
{
|
|
_repository = repository;
|
|
_dbManager = dbManager;
|
|
_dictionaryDataService = dictionaryDataService;
|
|
OverideFuncs.GetListAsync = GetList;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 物料清单列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<dynamic> GetList(VisualDevModelListQueryInput input)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
Dictionary<string, object>? queryJson = (input==null || string.IsNullOrEmpty(input.queryJson)) ? null : input.queryJson.ToObject<Dictionary<string, object>>();
|
|
string materialInfo = queryJson?["query_info"]?.ToString() ?? "";
|
|
var list = await db.Queryable<BasEbomH, BasMaterial, BasRouteH>((a, b, c) => new object[]
|
|
{
|
|
JoinType.Left, a.material_id == b.id,
|
|
JoinType.Left, a.route_id == c.id,
|
|
})
|
|
.WhereIF(!string.IsNullOrEmpty(materialInfo),(a,b,c)=>b.code.Contains(materialInfo) || b.name.Contains(materialInfo))
|
|
.Select((a, b, c) => new EbomListOutput
|
|
{
|
|
id = a.id,
|
|
material_id = b.code + "-" + b.name,
|
|
material_id_id = b.id,
|
|
status = SqlFunc.IIF(a.status == "0", "禁用", "启用"),
|
|
descrip = a.descrip,
|
|
quantity = a.quantity,
|
|
version = a.version,
|
|
route_id = c.name,
|
|
route_id_id = c.id,
|
|
|
|
}).ToPagedListAsync((input?.currentPage ?? 1), (input?.pageSize ?? 50));
|
|
|
|
return PageResult<EbomListOutput>.SqlSugarPageResult(list);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取物料清单树.
|
|
/// </summary>
|
|
/// <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<BasRouteH>((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,
|
|
material_id_id = c.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 = !string.IsNullOrEmpty(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<BasRouteH>((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,
|
|
material_id_id = c.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 = !string.IsNullOrEmpty(it.material_id_unit_id) ? dic[it.material_id_unit_id].ToString() : "";
|
|
}).ToListAsync();
|
|
return data;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据物料ID获取版本号和工艺路线
|
|
/// </summary>
|
|
/// <param name="parameters">物料id materialId</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Dictionary<string,string>> GetEbomVersionAndRouteName(Dictionary<string,string> parameters)
|
|
{
|
|
string materialId = parameters["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<BasRouteH>((a,b)=>a.route_id==b.id)
|
|
.OrderByDescending((a,b)=>a.create_time)
|
|
.Where((a,b) => a.material_id == materialId)
|
|
.Select((a,b)=>new
|
|
{
|
|
a.id,
|
|
a.version,
|
|
b.name,
|
|
}).FirstAsync();
|
|
return new Dictionary<string,string>()
|
|
{
|
|
["version"] = ebom?.version ?? "",
|
|
["routeName"] = ebom?.name ?? "",
|
|
["routeId"] = ebom?.id ?? ""
|
|
,
|
|
};
|
|
}
|
|
}
|
|
} |