Tjiny
7 天以前 6d40f7c8b19efc612f824ee7e778d5be9f8382f5
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System;
using System.Linq;
using System.Web.Http;
using HH.WCS.Mobox3.RiDong.apiMethod;
using HH.WCS.Mobox3.RiDong.dispatch;
using HH.WCS.Mobox3.RiDong.dto;
using HH.WCS.Mobox3.RiDong.generalMethod;
using HH.WCS.Mobox3.RiDong.models;
using HH.WCS.Mobox3.RiDong.util;
using HH.WCS.Mobox3.RiDong.wms;
 
namespace HH.WCS.Mobox3.RiDong.api;
 
/// <summary>
/// 综合性接口
/// </summary>
public class SynthesizeController : ApiController
{
    /// <summary>
    /// 创建作业
    /// </summary>
    /// <remarks>存在中转货位(入库、出库、盘点入、盘点出)</remarks>
    /// <returns></returns>
    [HttpPost]
    public ApiModel.SimpleResult AddOperation(OperationDto input)
    {
        return SynthesizeService.AddOperation(input);
    }
 
    /// <summary>
    /// 作业取消
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    public ApiModel.SimpleResult CancelOperation(ApiModel.MoboxTaskBase model)
    {
        var result = new ApiModel.SimpleResult();
 
        var operation = AdoSqlMethod<Operation>.QueryFirst(p => p.S_CODE == model.TaskNo && p.N_B_STATE != 7);
 
        if (operation == null)
        {
            result.resultCode = -1;
            result.resultMsg = "当前任务号不存在或任务已取消";
            return result;
        }
 
        var tasks = AdoSqlMethod<Task>.QueryList(p => p.S_OP_CODE == operation.S_CODE);
 
        // 当前任务数量和当前未执行的任务数量一致的情况下,允许取消任务
        if (tasks.Count == tasks.Count(p => p.S_OP_CODE == operation.S_CODE && p.N_B_STATE < 3))
        {
            // 允许取消任务
            foreach (var task in tasks)
            {
                // 判断任务
                if (task.N_SCHEDULE_TYPE == 2 && task.N_B_STATE > 0 && task.N_B_STATE < 3)
                {
                    // 通知agv取消任务
                    NDCHelper.Cancel(task.S_CODE.Trim());
                }
 
                task.N_B_STATE = 5;
                task.S_B_STATE = "取消";
                task.T_MODIFY = DateTime.Now;
                task.T_END_TIME = DateTime.Now;
            }
 
            AdoSqlMethod<Task>.UpdateList(tasks, p => new { p.N_B_STATE, p.S_B_STATE, p.T_MODIFY, p.T_END_TIME });
 
            operation.N_B_STATE = 7;
            operation.S_B_STATE = "取消";
            operation.T_MODIFY = DateTime.Now;
            operation.T_END_TIME = DateTime.Now;
 
            AdoSqlMethod<Operation>.UpdateFirst(operation,
                p => new { p.N_B_STATE, p.S_B_STATE, p.T_MODIFY, p.T_END_TIME });
 
            var container = AdoSqlMethod<Container>.QueryFirst(p => p.S_CODE == operation.S_CNTR_CODE);
 
            // 修改容器状态
            container.T_MODIFY = DateTime.Now;
            container.N_LOCK_STATE = 0;
 
            string loc = "";
            // 解锁
            if (operation.N_TYPE == 1 || operation.N_TYPE == 3)
            {
                container.C_ENABLE = 'N';
                loc = operation.S_END_LOC;
            }
            else if (operation.N_TYPE == 2 || operation.N_TYPE == 4 || operation.N_TYPE == 5 || operation.N_TYPE == 6 || operation.N_TYPE == 7)
            {
                container.C_ENABLE = 'Y';
                loc = operation.S_START_LOC;
            }
 
            LocationHelper.UnLockLoc(loc);
 
            AdoSqlMethod<Container>.UpdateFirst(container, p => new { p.C_ENABLE, p.T_MODIFY, p.N_LOCK_STATE });
 
            result.resultCode = 0;
            result.resultMsg = "任务取消成功";
            return result;
        }
 
        result.resultCode = -1;
        result.resultMsg = "作业正在执行中,不可取消";
        return result;
    }
 
    /// <summary>
    /// 任务优先级
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    public ApiModel.SimpleResult TaskPriority(ApiModel.MoboxTaskBase model)
    {
        
        var result = new ApiModel.SimpleResult();
 
        var operation = AdoSqlMethod<Operation>.QueryFirst(p => p.S_CODE == model.TaskNo);
 
        if (operation == null)
        {
            result.resultCode = -1;
            result.resultMsg = $"作业不存在!,传递的任务号为{model.TaskNo}";
            return result;
        }
        
        // 任务存在,判断任务类型
        if (operation.N_TYPE is 1 or 3)
        {
            result.resultCode = -1;
            result.resultMsg = "入库类型任务无法提升优先级";
            return result;
        }
 
        var task = AdoSqlMethod<Task>.QueryFirst(p =>
            p.S_OP_CODE == operation.S_CODE && p.N_B_STATE < 2 && p.N_SCHEDULE_TYPE == 2);
 
        if (task == null)
        {
            result.resultCode = -1;
            result.resultMsg = "当前任务已完结或出错,无法提升优先级";
            return result;
        }
        
        // 未推送
        if (task.N_B_STATE == 0)
        {
            task.N_PRIORITY = 99;
            AdoSqlMethod<Task>.UpdateFirst(task, p => new { p.N_PRIORITY });
        }
        else
        {
            // 已推送,修改
            // 让agv放货
            NDCHelper.ChangePri(task.S_CODE, 99);
        }
        
        result.resultCode = 0;
        result.resultMsg = "优先级修改成功";
        return result;
    }
 
    /// <summary>
    /// 测试接口
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public Location QueryStereoscopicStorehouseLocation(string type)
    {
        var location = LocationMethod.QueryStereoscopicStorehouseLocation(type);
 
        // 加锁
        LocationHelper.LockLoc(location.S_CODE, 1);
 
        return location;
    }
}