IHeightWeghtLocationGetApp.cs
3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.Linq;
using Infrastructure;
using WebRepository;
namespace WebApp
{
/// <summary>
/// WCS根据高度和重量请求对应仓位接口App
/// </summary>
public partial class IHeightWeghtLocationGetApp : ApiApp
{
public IHeightWeghtLocationGetApp(IUnitWork unitWork, IAuth auth, BaseDBContext context) : base(unitWork, auth, context)
{
}
public Response<Location> GetHeightLocation(string taskno, decimal height, decimal weight)
{
using (var tran = _context.Database.BeginTransaction())
{
Response<Location> Response = new Response<Location>();
try
{
decimal? vweight = weight;
Location loc = new Location();
if (vweight != null && vweight.HasValue)
{
loc = _unitWork.Find<Location>(u => u.Status == LocationStatus.空仓位 && u.IsStop == false && u.MaxHeight == height && u.MaxWeight == vweight).OrderBy(a => a.Code).FirstOrDefault();
}
else
{
loc = _unitWork.Find<Location>(u => u.Status == LocationStatus.空仓位 && u.IsStop == false && u.MaxHeight == height).OrderBy(a => a.Code).FirstOrDefault();
}
if (loc == null)
{
Response.Code = 500;
Response.Status = false;
Response.Message = "仓库中没有与之高度和重量相匹配的空库位!";
}
else
{
//更新托盘回库的目的仓位
TaskDetail taskDetail = _unitWork.Find<TaskDetail>(u => u.TaskNo == taskno).FirstOrDefault();
taskDetail.DestinationLocation = loc.Code;
taskDetail.UpdateBy = "wms";
taskDetail.UpdateTime = DateTime.Now;
_unitWork.Update(taskDetail);
Location oldlocation = _unitWork.Find<Location>(u => u.Code == taskDetail.DestinationLocation).FirstOrDefault();
//释放原仓位
oldlocation.Status = LocationStatus.空仓位;
oldlocation.UpdateBy = "wms";
oldlocation.UpdateTime = DateTime.Now;
_unitWork.Update(oldlocation);
//锁定此新仓位
loc.Status = LocationStatus.任务锁定中;
loc.UpdateTime = DateTime.Now;
if (loc.UpdateBy == null)
{
loc.UpdateBy = "wms";
loc.UpdateTime = DateTime.Now;
}
_unitWork.Update(loc);
tran.Commit();
Response.Result = loc;
}
}
catch (Exception ex)
{
tran.Rollback();
Response.Code = 500;
Response.Status = false;
Response.Message = ex.Message;
}
return Response;
}
}
}
}