Commit abc0a987 by xin.yang

some update

parent 9964d254
......@@ -1127,5 +1127,74 @@ namespace Siger.ApiWMS.Controllers
return query.ToList().Concat(query.ToList().SelectMany(t => GetSonTypes(t.id, types)));
}
[HttpGet]
public IActionResult GetLocationTree(int warehouseid)
{
var locationTypes = locationtype.GetList(q => q.projectid == ProjectId && q.status == (int)RowState.Valid).ToList();
var sonLocationTypes = GetSonTypes(0, locationTypes).ToList();
var lastLocationId = sonLocationTypes.LastOrDefault()?.id ?? 0;
var allLocas = location.GetList(q => q.projectid == ProjectId && q.status == (int)RowState.Valid).ToList();
var locations = allLocas.Where(q => q.typeid == lastLocationId);
if(warehouseid > 0)
{
locations = locations.Where(q => q.storageid == warehouseid);
}
var locationTreeList = new List<LevelSectionTree>();
foreach(var loca in locations)
{
var locas = GetParentLocations(loca.id, allLocas.Select(q => new LevelSectionTree
{
id = q.id,
pid = q.parentid,
title = q.name,
name = q.name
}));
locationTreeList.AddRange(locas);
}
var locationModels = locations.Select(q => new LevelSectionTree
{
id = q.id,
pid = q.parentid,
title = q.name,
name = q.name
}).ToList();
var locationTree = locationTreeList.GroupBy(q => q.id).Select(q => q.FirstOrDefault()).ToList();
return new ObjectResult(ConvertToTree(locationTree));
}
private IEnumerable<LevelSectionTree> GetParentLocations(int pid, IEnumerable<LevelSectionTree> types)
{
var query = from c in types where c.id == pid select c;
return query.ToList().Concat(query.ToList().SelectMany(t => GetParentLocations(t.pid, types)));
}
private IList<LevelSectionTree> ConvertToTree(IEnumerable<LevelSectionTree> models)
{
var section = new Dictionary<int, LevelSectionTree>();
foreach (var item in models)
{
section.Add(item.id, item);
}
var result = new List<LevelSectionTree>();
foreach (var item in section.Values)
{
if (item.pid == 0)
{
result.Add(item);
}
else
{
if (section.ContainsKey(item.pid))
{
section[item.pid].AddChilrden(item);
}
}
}
return result;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment