去除引用common.props
This commit is contained in:
@@ -21,20 +21,20 @@ namespace Tnb.BasicData
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
public class BasMaterialService : IBasMaterialService,IDynamicApiController, ITransient
|
||||
public class BasMaterialService : IBasMaterialService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarRepository<BasMaterial> _repository;
|
||||
private readonly DataBaseManager _dbManager;
|
||||
private readonly IDictionaryDataService _dictionaryDataService;
|
||||
|
||||
|
||||
public BasMaterialService(
|
||||
ISqlSugarRepository<BasMaterial> repository,DataBaseManager dbManager,IDictionaryDataService dictionaryDataService)
|
||||
ISqlSugarRepository<BasMaterial> repository, DataBaseManager dbManager, IDictionaryDataService dictionaryDataService)
|
||||
{
|
||||
_repository = repository;
|
||||
_dbManager = dbManager;
|
||||
_dictionaryDataService = dictionaryDataService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 复制物料
|
||||
/// </summary>
|
||||
@@ -44,7 +44,7 @@ namespace Tnb.BasicData
|
||||
{
|
||||
string id = parameters["id"];
|
||||
BasMaterial basMaterial = await _repository.GetByIdAsync(id);
|
||||
|
||||
|
||||
List<BasMaterialUnit> materialUnits = await _repository.AsSugarClient().Queryable<BasMaterialUnit>().Where(x => x.material_id == id).ToListAsync();
|
||||
List<BasMaterialIntoFactorySpecifications> materialIntoFactorySpecifications = await _repository.AsSugarClient().Queryable<BasMaterialIntoFactorySpecifications>().Where(x => x.material_id == id).ToListAsync();
|
||||
|
||||
@@ -53,27 +53,26 @@ namespace Tnb.BasicData
|
||||
basMaterial.code += "_复制的请修改";
|
||||
basMaterial.name += "_复制的请修改";
|
||||
|
||||
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
||||
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
||||
{
|
||||
await _repository.InsertAsync(basMaterial);
|
||||
_ = await _repository.InsertAsync(basMaterial);
|
||||
foreach (BasMaterialUnit basMaterialUnit in materialUnits)
|
||||
{
|
||||
basMaterialUnit.id = SnowflakeIdHelper.NextId();
|
||||
basMaterialUnit.material_id = newId;
|
||||
}
|
||||
|
||||
|
||||
foreach (BasMaterialIntoFactorySpecifications basMaterialIntoFactorySpecification in materialIntoFactorySpecifications)
|
||||
{
|
||||
basMaterialIntoFactorySpecification.id = SnowflakeIdHelper.NextId();
|
||||
basMaterialIntoFactorySpecification.material_id = newId;
|
||||
}
|
||||
|
||||
await _repository.AsSugarClient().Insertable<BasMaterialUnit>(materialUnits).ExecuteCommandAsync();
|
||||
await _repository.AsSugarClient().Insertable<BasMaterialIntoFactorySpecifications>(materialIntoFactorySpecifications).ExecuteCommandAsync();
|
||||
_ = await _repository.AsSugarClient().Insertable<BasMaterialUnit>(materialUnits).ExecuteCommandAsync();
|
||||
_ = await _repository.AsSugarClient().Insertable<BasMaterialIntoFactorySpecifications>(materialIntoFactorySpecifications).ExecuteCommandAsync();
|
||||
});
|
||||
|
||||
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
||||
return result.IsSuccess ? "复制成功" : result.ErrorMessage;
|
||||
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "复制成功" : result.ErrorMessage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -84,14 +83,17 @@ namespace Tnb.BasicData
|
||||
[HttpPost]
|
||||
public async Task<dynamic> GetMaterialSelectInfo(MaterialSelectQueryInput queryInput)
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
ISqlSugarClient db = _repository.AsSugarClient();
|
||||
if (!string.IsNullOrEmpty(queryInput.ebom_id))
|
||||
{
|
||||
List<string> ids = await GetAllChildrenMaterialId(queryInput.ebom_id,0);
|
||||
List<string> ids = await GetAllChildrenMaterialId(queryInput.ebom_id, 0);
|
||||
BasEbomH ebom = await db.Queryable<BasEbomH>().Where(x => x.id == queryInput.ebom_id).SingleAsync();
|
||||
if(ebom!=null && !string.IsNullOrEmpty(ebom.material_id))
|
||||
if (ebom != null && !string.IsNullOrEmpty(ebom.material_id))
|
||||
{
|
||||
ids.Add(ebom.material_id);
|
||||
var result = await db.Queryable<BasMaterial>()
|
||||
}
|
||||
|
||||
SqlSugarPagedList<MaterialSelectOutput> result = await db.Queryable<BasMaterial>()
|
||||
.LeftJoin<DictionaryTypeEntity>((a, b) => b.EnCode == DictConst.MeasurementUnit && b.DeleteMark == null)
|
||||
.LeftJoin<DictionaryDataEntity>((a, b, c) => c.DictionaryTypeId == b.Id && a.unit_id == c.EnCode)
|
||||
.WhereIF(!string.IsNullOrEmpty(queryInput.material_info), (a, b, c) => a.code.Contains(queryInput.material_info) || a.name.Contains(queryInput.material_info))
|
||||
@@ -107,11 +109,11 @@ namespace Tnb.BasicData
|
||||
}).ToPagedListAsync(queryInput.currentPage, queryInput.pageSize);
|
||||
|
||||
return PageResult<MaterialSelectOutput>.SqlSugarPageResult(result);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = await db.Queryable<BasMaterial>()
|
||||
SqlSugarPagedList<MaterialSelectOutput> result = await db.Queryable<BasMaterial>()
|
||||
.LeftJoin<DictionaryTypeEntity>((a, b) => b.EnCode == DictConst.MeasurementUnit && b.DeleteMark == null)
|
||||
.LeftJoin<DictionaryDataEntity>((a, b, c) => c.DictionaryTypeId == b.Id && a.unit_id == c.EnCode)
|
||||
.WhereIF(!string.IsNullOrEmpty(queryInput.material_info), (a, b, c) => a.code.Contains(queryInput.material_info) || a.name.Contains(queryInput.material_info))
|
||||
@@ -132,16 +134,16 @@ namespace Tnb.BasicData
|
||||
[HttpPost]
|
||||
public async Task<dynamic> GetCanCreateSubWorkOrderMaterial(MaterialSelectQueryInput queryInput)
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
ISqlSugarClient db = _repository.AsSugarClient();
|
||||
if (!string.IsNullOrEmpty(queryInput.ebom_id))
|
||||
{
|
||||
List<string> ids = await GetAllChildrenMaterialId(queryInput.ebom_id,0);
|
||||
var result = await db.Queryable<BasMaterial>()
|
||||
List<string> ids = await GetAllChildrenMaterialId(queryInput.ebom_id, 0);
|
||||
SqlSugarPagedList<MaterialSelectOutput> result = await db.Queryable<BasMaterial>()
|
||||
.LeftJoin<DictionaryTypeEntity>((a, b) => b.EnCode == DictConst.MeasurementUnit && b.DeleteMark == null)
|
||||
.LeftJoin<DictionaryDataEntity>((a, b, c) => c.DictionaryTypeId == b.Id && a.unit_id == c.EnCode)
|
||||
.WhereIF(!string.IsNullOrEmpty(queryInput.material_info), (a, b, c) => a.code.Contains(queryInput.material_info) || a.name.Contains(queryInput.material_info))
|
||||
.WhereIF(!string.IsNullOrEmpty(queryInput.ebom_id), (a, b, c) => ids.Contains(a.id))
|
||||
.Where((a,b,c)=>a.is_create_sub_work_order=="1")
|
||||
.Where((a, b, c) => a.is_create_sub_work_order == "1")
|
||||
.Select((a, b, c) => new MaterialSelectOutput()
|
||||
{
|
||||
id = a.id,
|
||||
@@ -153,7 +155,7 @@ namespace Tnb.BasicData
|
||||
}).ToPagedListAsync(queryInput.currentPage, queryInput.pageSize);
|
||||
|
||||
return PageResult<MaterialSelectOutput>.SqlSugarPageResult(result);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -166,32 +168,32 @@ namespace Tnb.BasicData
|
||||
{
|
||||
string types = dic["types"];
|
||||
string[] typeArr = types.Split(",");
|
||||
List<BasMaterial> list = await _repository.AsSugarClient().Queryable<BasMaterial>().Where(x => x.state=="1").ToListAsync();
|
||||
List<BasMaterial> result = new List<BasMaterial>();
|
||||
foreach (var type in typeArr)
|
||||
List<BasMaterial> list = await _repository.AsSugarClient().Queryable<BasMaterial>().Where(x => x.state == "1").ToListAsync();
|
||||
List<BasMaterial> result = new();
|
||||
foreach (string type in typeArr)
|
||||
{
|
||||
result.AddRange(list.Where(x=>x.category_id.Contains(type)));
|
||||
result.AddRange(list.Where(x => x.category_id.Contains(type)));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<dynamic> GetMaterialByQueryJson(MaterialQueryInput input)
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
|
||||
if (input!=null && !string.IsNullOrEmpty(input.queryJson))
|
||||
ISqlSugarClient db = _repository.AsSugarClient();
|
||||
Dictionary<string, string>? queryJson = new();
|
||||
if (input != null && !string.IsNullOrEmpty(input.queryJson))
|
||||
{
|
||||
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input?.queryJson ?? "");
|
||||
}
|
||||
|
||||
List<string> typeList = new List<string>();
|
||||
if(!string.IsNullOrEmpty(input!.types))
|
||||
List<string> typeList = new();
|
||||
if (!string.IsNullOrEmpty(input!.types))
|
||||
{
|
||||
typeList = JsonConvert.DeserializeObject<List<string>>((input?.types??"")) ?? new List<string>();
|
||||
typeList = JsonConvert.DeserializeObject<List<string>>(input?.types ?? "") ?? new List<string>();
|
||||
}
|
||||
var query = db.Queryable<BasMaterial>()
|
||||
ISugarQueryable<BasMaterial> query = db.Queryable<BasMaterial>()
|
||||
.Where(x => x.state == "1")
|
||||
.WhereIF(queryJson != null && queryJson.ContainsKey("name"), x => x.name.Contains(queryJson!["name"]))
|
||||
.WhereIF(queryJson != null && queryJson.ContainsKey("code"), x => x.code.Contains(queryJson!["code"]))
|
||||
@@ -199,43 +201,51 @@ namespace Tnb.BasicData
|
||||
x => x.material_standard!.Contains(queryJson!["material_standard"]))
|
||||
.Select(x => x);
|
||||
|
||||
var list = new List<ISugarQueryable<BasMaterial>>();
|
||||
foreach (var type in typeList)
|
||||
List<ISugarQueryable<BasMaterial>> list = new();
|
||||
foreach (string type in typeList)
|
||||
{
|
||||
list.Add(query.Clone().Where(x=>x.category_id.Contains(type)));
|
||||
list.Add(query.Clone().Where(x => x.category_id.Contains(type)));
|
||||
}
|
||||
|
||||
if (list.Count <= 0)
|
||||
{
|
||||
var result = await query.ToPagedListAsync((input?.currentPage??1), (input?.pageSize??50));
|
||||
SqlSugarPagedList<BasMaterial> result = await query.ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
|
||||
return PageResult<BasMaterial>.SqlSugarPageResult(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = await db.UnionAll(list).Select<BasMaterial>().ToPagedListAsync((input?.currentPage??1), (input?.pageSize??50));
|
||||
SqlSugarPagedList<BasMaterial> result = await db.UnionAll(list).Select<BasMaterial>().ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
|
||||
return PageResult<BasMaterial>.SqlSugarPageResult(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取物料清单下所子集物料id
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<List<string>> GetAllChildrenMaterialId(string ebomId,int index)
|
||||
private async Task<List<string>> GetAllChildrenMaterialId(string ebomId, int index)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ebomId)) return new List<string>();
|
||||
List<string> ids = new List<string>();
|
||||
if (index++ > 10) return ids;
|
||||
var list = await _repository.AsSugarClient().Queryable<BasEbomD>().Where(x => x.ebom_id == ebomId)
|
||||
if (string.IsNullOrEmpty(ebomId))
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
List<string> ids = new();
|
||||
if (index++ > 10)
|
||||
{
|
||||
return ids;
|
||||
}
|
||||
|
||||
List<string> list = await _repository.AsSugarClient().Queryable<BasEbomD>().Where(x => x.ebom_id == ebomId)
|
||||
.Select<string>(x => x.material_id).ToListAsync();
|
||||
if (list != null && list.Count > 0)
|
||||
{
|
||||
foreach (var id in list)
|
||||
foreach (string id in list)
|
||||
{
|
||||
//获取最新创建的物料清单
|
||||
var ebom = await _repository.AsSugarClient().Queryable<BasEbomH>().Where(x=>x.material_id==id).OrderByDescending(x=>x.create_time).FirstAsync();
|
||||
ids.AddRange(await GetAllChildrenMaterialId(ebom?.id ?? "",index));
|
||||
BasEbomH ebom = await _repository.AsSugarClient().Queryable<BasEbomH>().Where(x => x.material_id == id).OrderByDescending(x => x.create_time).FirstAsync();
|
||||
ids.AddRange(await GetAllChildrenMaterialId(ebom?.id ?? "", index));
|
||||
}
|
||||
ids.AddRange(list);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user