Commit ac739fc3 by yiyu.li
parents ba0bbbf6 84bfe60b
...@@ -1001,48 +1001,71 @@ namespace Siger.ApiWMS.Controllers ...@@ -1001,48 +1001,71 @@ namespace Siger.ApiWMS.Controllers
var Location = req.storeArr.FirstOrDefault(q => q.id == locationType.id); var Location = req.storeArr.FirstOrDefault(q => q.id == locationType.id);
if (Location == null) 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, throw new BadRequestException(RequestEnum.DataExist);
parentid = parentid, }
name = "", if (tmp == null)
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); tmp = new siger_wms_storage_location
continue; {
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 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); 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)
{ {
int id = 0; int id = tmp.id;
location.Insert(tmp); if(id == 0)
if (_unitOfWork.Commit() <= 0)
{ {
return id; location.Insert(tmp);
if (_unitOfWork.Commit() <= 0)
{
return id;
}
} }
//更新编号、层级名称 //更新编号、层级名称
...@@ -1075,7 +1098,7 @@ namespace Siger.ApiWMS.Controllers ...@@ -1075,7 +1098,7 @@ namespace Siger.ApiWMS.Controllers
location.Update(tmp); location.Update(tmp);
if (_unitOfWork.Commit() <= 0) if (_unitOfWork.Commit() <= 0)
{ {
return id; return 0;
} }
return tmp.id; return tmp.id;
...@@ -1121,7 +1144,7 @@ namespace Siger.ApiWMS.Controllers ...@@ -1121,7 +1144,7 @@ namespace Siger.ApiWMS.Controllers
foreach (var Location in req.storeArr) 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 && 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); q.locationid == req.storeID.ToInt() && q.id != Location.locationid.ToInt() && q.storageid == req.warehouseid);
...@@ -1142,34 +1165,67 @@ namespace Siger.ApiWMS.Controllers ...@@ -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) foreach (var locationType in sonLocationTypes)
{ {
var Location = req.storeArr.FirstOrDefault(q => q.id == locationType.id); var Location = req.storeArr.FirstOrDefault(q => q.id == locationType.id);
if (Location == null) 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()); if (tmp == null)
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)
{ {
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.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) 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 ...@@ -23,7 +23,9 @@ namespace Siger.Middlelayer.Utility.ImportEntities
public string ID { get; set; } public string ID { get; set; }
[ExcelColumn("仓库名称")] [ExcelColumn("仓库名称")]
public string StorageName { get; set; } public string StorageName { get; set; }
/// <summary>
/// 仓库ID
/// </summary>
public int StorageId { get; set; } public int StorageId { get; set; }
public List<LocationModels> Locations { get; set; } = new List<LocationModels>(); public List<LocationModels> Locations { get; set; } = new List<LocationModels>();
...@@ -31,9 +33,13 @@ namespace Siger.Middlelayer.Utility.ImportEntities ...@@ -31,9 +33,13 @@ namespace Siger.Middlelayer.Utility.ImportEntities
public class LocationModels public class LocationModels
{ {
/// <summary>
/// 储位类别ID
/// </summary>
public int LocationType { get; set; } public int LocationType { get; set; }
/// <summary>
/// 储位
/// </summary>
public string Location { get; set; } public string Location { get; set; }
} }
} }
...@@ -103,7 +103,7 @@ namespace Siger.Middlelayer.AccRepository.Repositories ...@@ -103,7 +103,7 @@ namespace Siger.Middlelayer.AccRepository.Repositories
else else
{ {
var entities = query.Where(expression).GroupBy(q=>q.fixtureguid).Select(q=>q.FirstOrDefault()).OrderByDescending(q => q.id).Skip((page - 1) * pagesize).Take(pagesize).AsNoTracking().ToList(); var entities = query.Where(expression).GroupBy(q=>q.fixtureguid).Select(q=>q.FirstOrDefault()).OrderByDescending(q => q.id).Skip((page - 1) * pagesize).Take(pagesize).AsNoTracking().ToList();
var totalCount = query.Where(expression).GroupBy(q => q.fixtureguid).Select(q => q.FirstOrDefault()).Count(); var totalCount = query.Where(expression).GroupBy(q => q.fixtureguid).Count();
return new PagedCollectionResult<ResponseAumationFixtureToolsAssemblys>(entities, totalCount); return new PagedCollectionResult<ResponseAumationFixtureToolsAssemblys>(entities, totalCount);
} }
} }
......
...@@ -7,6 +7,7 @@ using Siger.Middlelayer.Common; ...@@ -7,6 +7,7 @@ using Siger.Middlelayer.Common;
using Siger.Middlelayer.Common.Extensions; using Siger.Middlelayer.Common.Extensions;
using Siger.Middlelayer.Common.Helpers; using Siger.Middlelayer.Common.Helpers;
using Siger.Middlelayer.Common.ModuleEnum; using Siger.Middlelayer.Common.ModuleEnum;
using Siger.Middlelayer.Log;
using Siger.Middlelayer.Utility.ExcelImport; using Siger.Middlelayer.Utility.ExcelImport;
using Siger.Middlelayer.Utility.ImportEntities; using Siger.Middlelayer.Utility.ImportEntities;
using Siger.Middlelayer.WmsRepository.Entities; using Siger.Middlelayer.WmsRepository.Entities;
...@@ -77,8 +78,9 @@ namespace Siger.Middlelayer.WmsRepository.Repositories ...@@ -77,8 +78,9 @@ namespace Siger.Middlelayer.WmsRepository.Repositories
return str; 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 locationTypeId = sonLocationTypes.LastOrDefault()?.id ?? 0;
var ids = new List<int>(); var ids = new List<int>();
...@@ -90,47 +92,71 @@ namespace Siger.Middlelayer.WmsRepository.Repositories ...@@ -90,47 +92,71 @@ namespace Siger.Middlelayer.WmsRepository.Repositories
{ {
return false; 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, msg = (int)RequestEnum.DataExist;
parentid = parentid, return false;
name = "", }
realname = Location.Location, if (tmp == null)
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); tmp = new siger_wms_storage_location
continue; {
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 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); continue;
dbContext.siger_wms_storage_location.Remove(entity); }
else
{
return false;
} }
return false;
} }
} }
return true; return true;
} }
private int InsertLocation(siger_wms_storage_location tmp, string waveHouseName, int projectid) private int InsertLocation(siger_wms_storage_location tmp, string waveHouseName, int projectid)
{ {
int id = 0; int id = tmp.id;
dbContext.siger_wms_storage_location.Add(tmp); if (id == 0)
if (dbContext.SaveChanges() <= 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 ...@@ -163,7 +189,7 @@ namespace Siger.Middlelayer.WmsRepository.Repositories
dbContext.siger_wms_storage_location.Update(tmp); dbContext.siger_wms_storage_location.Update(tmp);
if (dbContext.SaveChanges() <= 0) if (dbContext.SaveChanges() <= 0)
{ {
return id; return 0;
} }
return tmp.id; return tmp.id;
...@@ -256,14 +282,22 @@ namespace Siger.Middlelayer.WmsRepository.Repositories ...@@ -256,14 +282,22 @@ namespace Siger.Middlelayer.WmsRepository.Repositories
{ {
try 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)); return new CommonImportResult(0, string.Join(";", errors));
} }
} }
catch(Exception) catch(Exception e)
{ {
Logger.WriteLineError(e.Message);
errors.Add($"{rowIndex},{(int)RequestEnum.ImportFailed}"); errors.Add($"{rowIndex},{(int)RequestEnum.ImportFailed}");
return new CommonImportResult(0, string.Join(";", errors)); 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