Commit e333ca53 by xin.yang

fix bug

parent 13ff601f
......@@ -995,6 +995,7 @@ namespace Siger.ApiWMS.Controllers
}
var ids = new List<int>();
var delIds = new List<int>();
var parentid = 0;
foreach (var locationType in sonLocationTypes)
{
......@@ -1028,7 +1029,7 @@ namespace Siger.ApiWMS.Controllers
status = req.status == (int)RowState.Valid ? (int)RowState.Valid : (int)RowState.Invalid,
locationid = Location.id == locationTypeId ? req.storeID.ToInt() : 0
};
parentid = InsertLocation(tmp, waveHouse.name);
parentid = InsertLocation(tmp, waveHouse.name, delIds);
if (parentid > 0)
{
ids.Add(parentid);
......@@ -1043,7 +1044,7 @@ namespace Siger.ApiWMS.Controllers
{
tmp.status = req.status == (int)RowState.Valid ? (int)RowState.Valid : (int)RowState.Invalid;
tmp.locationid = Location.id == locationTypeId ? req.storeID.ToInt() : 0;
parentid = InsertLocation(tmp, waveHouse.name);
parentid = InsertLocation(tmp, waveHouse.name, delIds);
if (parentid > 0)
{
continue;
......@@ -1056,7 +1057,7 @@ namespace Siger.ApiWMS.Controllers
}
return new ObjectResult(CommonEnum.Succefull);
}
private int InsertLocation(siger_wms_storage_location tmp, string waveHouseName)
private int InsertLocation(siger_wms_storage_location tmp, string waveHouseName, List<int> delIds)
{
int id = tmp.id;
if(id == 0)
......@@ -1066,6 +1067,10 @@ namespace Siger.ApiWMS.Controllers
{
return id;
}
else
{
delIds.Add(tmp.id);
}
}
//更新编号、层级名称
......@@ -1165,21 +1170,24 @@ namespace Siger.ApiWMS.Controllers
//}
}
var ids = new List<int>();//只有新增的数据才会加进这个列表,可以用于判断是否有新增数据
var ids = new List<int>();
var delIds = new List<int>();
var parentid = 0;
foreach (var locationType in sonLocationTypes)
{
var Location = req.storeArr.FirstOrDefault(q => q.id == locationType.id);
if (Location == null)
{
DelInsertFailLocations(delIds);
throw new BadRequestException(CommonEnum.Fail);
}
var tmp1 = location.Get(q => q.projectid == ProjectId && q.status == (int)RowState.Valid && q.realname == Location.val &&
q.typeid == locationType.id && q.parentid == parentid && q.storageid == req.warehouseid && q.id != Location.locationid.ToInt());
var tmp = location.Get(q => q.projectid == ProjectId && q.status == (int)RowState.Valid && q.realname == Location.val &&
q.typeid == locationType.id && q.parentid == parentid && q.storageid == req.warehouseid && q.id == Location.locationid.ToInt());
var tmp = location.Get(q => q.projectid == ProjectId && q.status == (int)RowState.Valid && (q.realname != Location.val && q.typeid == locationType.id ||
q.realname == Location.val) && q.typeid == locationType.id && q.parentid == parentid && q.storageid == req.warehouseid && q.id == Location.locationid.ToInt());
if (tmp1 != null && tmp1.typeid == locationTypeId && !ids.Any() && tmp1.name == Location.val)
{
DelInsertFailLocations(delIds);
throw new BadRequestException(RequestEnum.DataExist);
}
if (tmp == null)
......@@ -1207,10 +1215,11 @@ namespace Siger.ApiWMS.Controllers
q.locationid == req.storeID.ToInt() && q.storageid == req.warehouseid);
if (locationIdExist != null)
{
DelInsertFailLocations(delIds);
throw new BadRequestException(RequestEnum.IDExist);
}
}
parentid = InsertLocation(tmp, waveHouse.name);
parentid = InsertLocation(tmp, waveHouse.name, delIds);
if (parentid > 0)
{
ids.Add(parentid);
......@@ -1218,35 +1227,66 @@ namespace Siger.ApiWMS.Controllers
}
else
{
DelInsertFailLocations(delIds);
throw new BadRequestException(CommonEnum.Fail);
}
}
else
{
if (Location.id == locationTypeId)
if (Location.id == locationTypeId && !delIds.Any())//如果父级无新增,delIds无数据代表父级无新增
{
var locationIdExist = location.Get(q => q.projectid == ProjectId && q.status == (int)RowState.Valid && q.typeid == locationTypeId &&
q.locationid == req.storeID.ToInt() && q.id != Location.locationid.ToInt() && q.storageid == req.warehouseid);
if (locationIdExist != null)
{
DelInsertFailLocations(delIds);
throw new BadRequestException(RequestEnum.IDExist);
}
var locationIdExist1 = location.Get(q => q.projectid == ProjectId && q.status == (int)RowState.Valid && q.typeid == locationTypeId &&
q.realname == Location.val && q.id != Location.locationid.ToInt() && q.storageid == req.warehouseid);
if (locationIdExist1 != null)
{
DelInsertFailLocations(delIds);
throw new BadRequestException(RequestEnum.DataExist);
}
}
else if (Location.id == locationTypeId)//如果父级有新增
{
var locationIdExist = location.Get(q => q.projectid == ProjectId && q.status == (int)RowState.Valid && q.typeid == locationTypeId &&
q.locationid == req.storeID.ToInt() && q.id != Location.locationid.ToInt() && q.storageid == req.warehouseid);
if (locationIdExist != null)
{
DelInsertFailLocations(delIds);
throw new BadRequestException(RequestEnum.IDExist);
}
}
tmp.status = req.status == (int)RowState.Valid ? (int)RowState.Valid : (int)RowState.Invalid;
tmp.locationid = Location.id == locationTypeId ? req.storeID.ToInt() : 0;
parentid = InsertLocation(tmp, waveHouse.name);
tmp.realname = Location.val;
parentid = InsertLocation(tmp, waveHouse.name, delIds);
if (parentid > 0)
{
continue;
}
else
{
DelInsertFailLocations(delIds);
throw new BadRequestException(CommonEnum.Fail);
}
}
}
return new ObjectResult(CommonEnum.Succefull);
}
private void DelInsertFailLocations(List<int> DelIds)
{
foreach(var id in DelIds)
{
var entity = location.Get(q => q.projectid == ProjectId && q.status == (int)RowState.Valid && id == q.id);
entity.status = (int)RowState.Invalid;
location.Update(entity);
_unitOfWork.Commit();
}
}
private IEnumerable<siger_wms_storage_location_type> GetSonTypes(int id, List<siger_wms_storage_location_type> types)
{
var query = from c in types where c.parentid == id select c;
......
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