Commit 1d4af520 by xin.yang

fix bug

parent 66ac59bd
......@@ -1001,48 +1001,71 @@ namespace Siger.ApiWMS.Controllers
var Location = req.storeArr.FirstOrDefault(q => q.id == locationType.id);
if (Location == null)
{
throw new BadRequestException(CommonEnum.Fail);//TODO
throw new BadRequestException(CommonEnum.Fail);
}
var tmp = new siger_wms_storage_location
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);
if (tmp != null && tmp.typeid == locationTypeId && !ids.Any() && tmp.name == Location.val)
{
storageid = req.warehouseid,
parentid = parentid,
name = "",
realname = Location.val,
typeid = Location.id,
serial_number = Utility.GenSerialNumber(),
creator = UserId,
create_time = DateTime.Now,
updator = UserId,
update_time = DateTime.Now,
projectid = ProjectId,
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);
if (parentid > 0)
throw new BadRequestException(RequestEnum.DataExist);
}
if (tmp == null)
{
ids.Add(parentid);
continue;
tmp = new siger_wms_storage_location
{
id = 0,
storageid = req.warehouseid,
parentid = parentid,
name = "",
realname = Location.val,
typeid = Location.id,
serial_number = Utility.GenSerialNumber(),
creator = UserId,
create_time = DateTime.Now,
updator = UserId,
update_time = DateTime.Now,
projectid = ProjectId,
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);
if (parentid > 0)
{
ids.Add(parentid);
continue;
}
else
{
throw new BadRequestException(CommonEnum.Fail);
}
}
else
{
foreach (var id in ids)
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);
if (parentid > 0)
{
location.Delete(id);
continue;
}
else
{
throw new BadRequestException(CommonEnum.Fail);
}
throw new BadRequestException(CommonEnum.Fail);//TODO
}
}
return new ObjectResult(CommonEnum.Succefull);
}
private int InsertLocation(siger_wms_storage_location tmp, string waveHouseName)
{
int id = 0;
location.Insert(tmp);
if (_unitOfWork.Commit() <= 0)
int id = tmp.id;
if(id == 0)
{
return id;
location.Insert(tmp);
if (_unitOfWork.Commit() <= 0)
{
return id;
}
}
//更新编号、层级名称
......@@ -1075,7 +1098,7 @@ namespace Siger.ApiWMS.Controllers
location.Update(tmp);
if (_unitOfWork.Commit() <= 0)
{
return id;
return 0;
}
return tmp.id;
......@@ -1121,7 +1144,7 @@ namespace Siger.ApiWMS.Controllers
foreach (var Location in req.storeArr)
{
if(Location.id == locationTypeId)
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);
......@@ -1142,34 +1165,67 @@ namespace Siger.ApiWMS.Controllers
//}
}
var ids = new List<int>();
var ids = new List<int>();//只有新增的数据才会加进这个列表,可以用于判断是否有新增数据
var parentid = 0;
foreach (var locationType in sonLocationTypes)
{
var Location = req.storeArr.FirstOrDefault(q => q.id == locationType.id);
if (Location == null)
{
throw new BadRequestException(CommonEnum.Fail);//TODO
throw new BadRequestException(CommonEnum.Fail);
}
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);
if (tmp != null && tmp.typeid == locationTypeId && !ids.Any() && tmp.name == Location.val && tmp.id != Location.locationid.ToInt())
{
throw new BadRequestException(RequestEnum.DataExist);
}
var tmp = location.Get(q => q.projectid == ProjectId && q.id == Location.locationid.ToInt());
tmp.status = req.status == (int)RowState.Valid ? (int)RowState.Valid : (int)RowState.Invalid;
tmp.storageid = req.warehouseid;
tmp.locationid = req.storeID.ToInt();
tmp.realname = Location.val;
if (tmp.parentid == 0)
if (tmp == null)
{
tmp = new siger_wms_storage_location
{
id = 0,
storageid = req.warehouseid,
parentid = parentid,
name = "",
realname = Location.val,
typeid = Location.id,
serial_number = Utility.GenSerialNumber(),
creator = UserId,
create_time = DateTime.Now,
updator = UserId,
update_time = DateTime.Now,
projectid = ProjectId,
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);
if (parentid > 0)
{
ids.Add(parentid);
continue;
}
else
{
throw new BadRequestException(CommonEnum.Fail);
}
}
else
{
tmp.status = req.status == (int)RowState.Valid ? (int)RowState.Valid : (int)RowState.Invalid;
tmp.locationid = Location.id == locationTypeId ? req.storeID.ToInt() : 0;
tmp.name = $"{waveHouse.name} -> {tmp.realname}";
parentid = InsertLocation(tmp, waveHouse.name);
if (parentid > 0)
{
continue;
}
else
{
throw new BadRequestException(CommonEnum.Fail);
}
}
location.Update(tmp);
}
if (_unitOfWork.Commit() > 0)
{
return new ObjectResult(CommonEnum.Succefull);
}
else
{
throw new BadRequestException(CommonEnum.Fail);
}
return new ObjectResult(CommonEnum.Succefull);
}
private IEnumerable<siger_wms_storage_location_type> GetSonTypes(int id, List<siger_wms_storage_location_type> types)
{
......
......@@ -23,7 +23,9 @@ namespace Siger.Middlelayer.Utility.ImportEntities
public string ID { get; set; }
[ExcelColumn("仓库名称")]
public string StorageName { get; set; }
/// <summary>
/// 仓库ID
/// </summary>
public int StorageId { get; set; }
public List<LocationModels> Locations { get; set; } = new List<LocationModels>();
......@@ -31,9 +33,13 @@ namespace Siger.Middlelayer.Utility.ImportEntities
public class LocationModels
{
/// <summary>
/// 储位类别ID
/// </summary>
public int LocationType { get; set; }
/// <summary>
/// 储位
/// </summary>
public string Location { get; set; }
}
}
......@@ -7,6 +7,7 @@ using Siger.Middlelayer.Common;
using Siger.Middlelayer.Common.Extensions;
using Siger.Middlelayer.Common.Helpers;
using Siger.Middlelayer.Common.ModuleEnum;
using Siger.Middlelayer.Log;
using Siger.Middlelayer.Utility.ExcelImport;
using Siger.Middlelayer.Utility.ImportEntities;
using Siger.Middlelayer.WmsRepository.Entities;
......@@ -77,8 +78,9 @@ namespace Siger.Middlelayer.WmsRepository.Repositories
return str;
}
private bool InsertData(ImportStorageLocations locationEntity, int projectid, int userid, List<siger_wms_storage_location_type> sonLocationTypes)
private bool InsertData(ImportStorageLocations locationEntity, int projectid, int userid, List<siger_wms_storage_location_type> sonLocationTypes,out int msg)
{
msg = 0;
var locationTypeId = sonLocationTypes.LastOrDefault()?.id ?? 0;
var ids = new List<int>();
......@@ -90,47 +92,71 @@ namespace Siger.Middlelayer.WmsRepository.Repositories
{
return false;
}
var tmp = new siger_wms_storage_location
var tmp = dbContext.siger_wms_storage_location.FirstOrDefault(q => q.projectid == projectid && q.status == (int)RowState.Valid && q.realname == Location.Location &&
q.typeid == locationType.id && q.parentid == parentid && q.storageid == locationEntity.StorageId);
if (tmp != null && tmp.typeid == locationTypeId && !ids.Any() && tmp.name == Location.Location)
{
storageid = locationEntity.StorageId,
parentid = parentid,
name = "",
realname = Location.Location,
typeid = Location.LocationType,
serial_number = GenSerialNumber(),
creator = userid,
create_time = DateTime.Now,
updator = userid,
update_time = DateTime.Now,
projectid = projectid,
status = (int)RowState.Valid,
locationid = Location.LocationType == locationTypeId ? locationEntity.ID.ToInt() : 0
};
parentid = InsertLocation(tmp, locationEntity.StorageName, projectid);
if (parentid > 0)
msg = (int)RequestEnum.DataExist;
return false;
}
if (tmp == null)
{
ids.Add(parentid);
continue;
tmp = new siger_wms_storage_location
{
id = 0,
storageid = locationEntity.StorageId,
parentid = parentid,
name = "",
realname = Location.Location,
typeid = Location.LocationType,
serial_number = GenSerialNumber(),
creator = userid,
create_time = DateTime.Now,
updator = userid,
update_time = DateTime.Now,
projectid = projectid,
status = (int)RowState.Valid,
locationid = Location.LocationType == locationTypeId ? locationEntity.ID.ToInt() : 0
};
parentid = InsertLocation(tmp, locationEntity.StorageName, projectid);
if (parentid > 0)
{
ids.Add(parentid);
continue;
}
else
{
return false;
}
}
else
{
foreach (var id in ids)
tmp.status = (int)RowState.Valid;
tmp.locationid = Location.LocationType == locationTypeId ? locationEntity.ID.ToInt() : 0;
parentid = InsertLocation(tmp, locationEntity.StorageName, projectid);
if (parentid > 0)
{
var entity = dbContext.siger_wms_storage_location.FirstOrDefault(q => q.id == id);
dbContext.siger_wms_storage_location.Remove(entity);
continue;
}
else
{
return false;
}
return false;
}
}
return true;
}
private int InsertLocation(siger_wms_storage_location tmp, string waveHouseName, int projectid)
{
int id = 0;
dbContext.siger_wms_storage_location.Add(tmp);
if (dbContext.SaveChanges() <= 0)
int id = tmp.id;
if (id == 0)
{
return id;
dbContext.siger_wms_storage_location.Add(tmp);
if (dbContext.SaveChanges() <= 0)
{
return id;
}
}
//更新编号、层级名称
......@@ -163,7 +189,7 @@ namespace Siger.Middlelayer.WmsRepository.Repositories
dbContext.siger_wms_storage_location.Update(tmp);
if (dbContext.SaveChanges() <= 0)
{
return id;
return 0;
}
return tmp.id;
......@@ -256,14 +282,22 @@ namespace Siger.Middlelayer.WmsRepository.Repositories
{
try
{
if(!InsertData(loca, projectid, userid, locationTypes))
if (!InsertData(loca, projectid, userid, locationTypes, out int msg))
{
errors.Add($"{rowIndex},{(int)RequestEnum.ImportFailed}");
if (msg > 0)
{
errors.Add($"{rowIndex},{msg}");
}
else
{
errors.Add($"{rowIndex},{(int)RequestEnum.ImportFailed}");
}
return new CommonImportResult(0, string.Join(";", errors));
}
}
catch(Exception)
catch(Exception e)
{
Logger.WriteLineError(e.Message);
errors.Add($"{rowIndex},{(int)RequestEnum.ImportFailed}");
return new CommonImportResult(0, string.Join(";", errors));
}
......
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