Commit 0f3cbbc5 by 任天宇

优化设置包裹接口

parent add08e08
......@@ -372,18 +372,28 @@ namespace Kivii.Samples
}
var exists = conn.SelectByIds<Sample>(samples.ConvertAll(p => p.Kvid));
exists.ThrowIfNullOrEmpty("未找到要打包的样品信息!");
exists.Exists(o => o.PackageKvid != Guid.Empty).ThrowIfTrue("存在样品已经打包!");
//exists.Exists(o => o.DealTime < DateTime.Parse("2023-06-25")).ThrowIfTrue("委托时间在2023-06-25以前的样品请使用老系统退样!!");
if (exists.Exists(o => o.PackageKvid != Guid.Empty))
{
var error = string.Empty;
foreach (var item in exists)
{
if (item.PackageKvid != Guid.Empty)
{
item.CurrentPackage = item.GetCurrentPackage();
if (item.CurrentPackage != null)
{
if (item.CurrentPackage.PackageName.IsNullOrEmpty()) error += $"样品{item.Name}已打包:{item.PackageName};";
else error += $"样品{item.Name}已打包:{item.CurrentPackage.Name},库位:{item.CurrentPackage.PackageName};";
}
else
{
error += $"样品{item.Name}已打包:{item.PackageName},但未找到此箱号信息;";
}
}
}
throw new Exception(error);
}
var packageArea = package.PackageName;
//package.PackageName = string.Empty;
//var local = conn.Single<Location>(o => o.InternalCode == location.InternalCode);
//(local == null).ThrowIfTrue($"未找到{location.InternalCode}目的地点配置信息!");
//var existPackage = conn.SingleById<Sample>(package.Kvid);
//if (existPackage != null)
//{
// if (existPackage.Type == SampleType.Package) package = existPackage;
//}
//var currentRoutes = conn.Select<Route>(o => Sql.In(o.SampleKvid, exists.ConvertAll(p => p.Kvid)) && o.NextLocationKvid == Guid.Empty);
var rtns = new List<Sample>();
IDbTransaction trans = null;//事务,如果外部来了Connection,不生成事务
if (useTransaction)
......
......@@ -105,6 +105,51 @@ namespace Kivii.Samples.Transforms
#endregion
[RequiresAnyRole(SystemRoles.Everyone)]
[Api(Description = "生成包裹")]
public class SamplePackageInit : RestfulExecution<Sample>
{
public bool AutoCreate { get; set; }
public string PackageName { get; set; }
public bool IncludeLocation { get; set; }
public bool IncludeRoutes { get; set; }
public override object OnExecution(IRequest req, IResponse res)
{
PackageName.ThrowIfNullOrEmpty("请输入包裹名称以查询!");
var rtns = new RestfulReadResponse<Sample>();
var conn = KiviiContext.GetOpenedDbConnection<Sample>();
var exist = conn.Single<Sample>(o => o.Name == PackageName && o.Type == SampleType.Package);
if (exist != null)
{
rtns.Result = exist;
}
else if(AutoCreate)
{
var item = new Sample();
item.Name = PackageName;
item.Type = SampleType.Package;
item.OperateTime = DateTime.Now;
conn.Insert(item);
item.RemoveAllOnlyProperties();
rtns.Result = item;
}
if (rtns.Result != null)
{
if (IncludeLocation)
{
rtns.Result.CurrentLocation = rtns.Result.GetCurrentLocation();
}
if (IncludeRoutes)
{
rtns.Result.Routes = rtns.Result.GetRoutes();
}
}
return rtns;
}
}
[RequiresAnyRole(SystemRoles.Everyone)]
[Api(Description ="生成样品")]
public class SampleAccept : RestfulExecution<Sample>
{
......
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