lzh
2025-06-19 3a6436e0c88042c6ce8dca2fe8adb0109f0ad9e4
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
--[[
 编码: GT-100-13
 名称: 国自任务回报
 作者: LZH
 入口函数:TaskStatus
 功能说明: 接收国自的任务返回状态
    输入数据:                                                                                        
    {    
        "feed_no": "xxx",  唯一码,用于接口校验,默认生成GUID
        "feed_type": "xxx",  反馈类型 1=任务开始;2=任务完成;3=任务异常;4=任务取消;5=任务更改(待定)6=货物节点
        "task_type": "xxx" ,  任务类型 1=货物入库;2=货物出库;3=托盘组入库;4=托盘组出库;5=移动(不过库位);6=移库
        "task_no": "xxx",  任务号 单托盘唯一任务号
        "mat_code": "xxx", 货物RFID
        "cur_station_no": "xxx", 当前位置
        "weight": "xxx", 称重重量
        "feed_time": "xxx" 反馈时间
    }
 
    处理逻辑
    -- step1 解析接口传递的 datajson 参数
    -- step2 校验必传字段是否为空,为空则报错
    -- step3 反馈类型 2 设置任务完成 3 报错 4 设置任务状态为取消并解锁
 变更历史:
    V1.0 LZH 20250121 feed_type = 3则更新工位异常信息
    V2.0 LZH 20250213 新增称重重量字段和类型
 --]]
require("WMS-Equipment")
wms_cntr = require("wms_container")
require("GT-Base")
wms_task = require("wms_task")
function GZTaskStatus(strLuaDEID)
    local nRet, in_date, strRetInfo
    -- step1 获取接口数据
    nRet, in_date = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WCStoreCallback 无法获取数据包!" .. in_date) end
 
 
    -- step2 判断 必填项 是否都有值?没值报错返回
    local task_no = in_date.task_no
    if (task_no == nil or task_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "任务号不能为空!") end
    local cntr_code = in_date.cntr_code
    if (cntr_code == nil or cntr_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "RFID不能为空!") end
    local feed_type = tonumber(in_date.feed_type)
    if (feed_type == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "反馈类型不能为空!") end
    local task_type = tonumber(in_date.task_type)
    if (task_type == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "任务类型不能为空!") end
    local cur_station_no = in_date.cur_station_no -- 当前位置
    -- V2.0 LZH 新增重量字段
    local weight = in_date.weight                 -- 称重重量
    local err_msg = in_date.err_msg               -- 反馈类型为3时传的工位异常信息
 
    -- 获取任务中的容器编码和起始货位编码
    local task
    nRet, task = wms_task.GetInfo(strLuaDEID, task_no)
    if (nRet ~= 0) then return end
 
 
    if (task.bs_state == 3) then
        lua.Error(strLuaDEID, debug.getinfo(1), "任务已完成!")
    elseif (task.bs_state == 4) then
        lua.Error(strLuaDEID, debug.getinfo(1), "任务异常!")
    end
 
    -- 反馈类型 2 设置任务完成 3 报错 4 设置任务状态为取消并解锁
    if (feed_type == 2) then
        lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task)
        lua.Debug(strLuaDEID, debug.getinfo(1), '国自任务反馈参数:', in_date)
        -- 校验终点位置是否传参
        if (task.op_name == '粉料入库' or task.op_name == '立库出库' or task.op_name == '采购退货' or task.op_name == '呼叫空托') then
            if (cur_station_no == nil or cur_station_no == '') then
                lua.Error(strLuaDEID, debug.getinfo(1), "终点未传参!")
            end
            cur_station_no = wms_base.Get_sConst(strLuaDEID, cur_station_no)
            lua.Debug(strLuaDEID, debug.getinfo(1), 'cur_station_no:', cur_station_no)
            task.end_loc_code = cur_station_no
            lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task)
            nRet, strRetInfo = wms_task.Update(strLuaDEID, task)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "更新任务终点失败!" .. strRetInfo) end
        end
 
 
        -- 出库无需绑定终点
        if (task.op_name == '立库出库' or task.op_name == '呼叫空托' or task.op_name == '采购退货' or task.op_name == '点对点出库') then
            -- 容器货位解绑
            nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, task.start_loc_code, cntr_code,
                "绑定解绑方法-系统",
                "完成")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end
        elseif (task.op_name == '移库') then
            -- 容器货位解绑
            nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, task.start_loc_code, cntr_code,
                "绑定解绑方法-系统",
                "完成")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end
 
            -- 容器货位绑定
            nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, task.end_loc_code, cntr_code, "绑定解绑方法-系统",
                "完成")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器绑定失败!' .. strRetInfo) end
        else
            -- 容器货位绑定
            nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, task.end_loc_code, cntr_code, "绑定解绑方法-系统",
                "完成")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器绑定失败!' .. strRetInfo) end
        end
 
        -- 强制任务完成
        nRet, strRetInfo = wms.wms_TaskFinish(strLuaDEID, task_no)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "任务编码='" .. task_no .. "'的任务设置完成失败!" .. strRetInfo) end
 
        -- 增加 任务动作 对象
        local task_action = m3.AllocObject(strLuaDEID, "Task_Action")
        task_action.task_code = task_no
        task_action.action_code = 2
        task_action.action = "国自搬运完成"
        task_action.eq_code = "system"
        task_action.eq_type_name = '完成'
        nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, task_action)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '创建【任务动作】对象失败!' .. strRetInfo) end
    elseif (feed_type == 3) then
        if (cur_station_no == nil or cur_station_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), '异常工位不能为空!') end
        cur_station_no = wms_base.Get_sConst(strLuaDEID, cur_station_no)
 
        -- 根据工位修改异常信息
        local condition = "S_START_LOC = '" .. cur_station_no .. "'"
        local strSetAttr = "S_ERR_MSG = '" .. err_msg .. "'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_PDA_Station", condition, strSetAttr)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "工位异常信息失败!" .. strRetInfo)
        end
    elseif (feed_type == 4) then
        lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task)
        lua.Debug(strLuaDEID, debug.getinfo(1), '国自任务反馈参数:', in_date)
        if (task.op_name == '国自空托回库') then
            -- 给取消的任务解锁
            nRet, strRetInfo = wms.wms_UnlockByTask(strLuaDEID, task_no)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_UnlockByTask 失败! " .. strRetInfo) end
            -- 设置任务状态为取消
            local condition = "S_CODE = '" .. task_no .. "'"
            local strSetAttr = "N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "任务状态-取消") .. ", S_B_STATE = '取消'"
            nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Task", condition, strSetAttr)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "设置任务状态失败!" .. strRetInfo)
            end
            -- 设置作业状态为取消
            local condition = "S_CODE = '" .. task.op_code .. "'"
            strSetAttr = "N_B_STATE = " .. wms_base.Get_nConst(strLuaDEID, "作业状态-取消") .. ", S_B_STATE = '取消'"
            nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Operation", condition, strSetAttr)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "设置作业状态失败!" .. strRetInfo)
            end
        end
    elseif (feed_type == 6) then
        if (cur_station_no == nil or cur_station_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), '节点工位不能为空!') end
        -- local cur_station_name = wms_base.GetDictItemName(strLuaDEID, "GT_TaskNode", cur_station_no)
        -- 增加 任务动作 对象
        local task_action = m3.AllocObject(strLuaDEID, "Task_Action")
        task_action.task_code = task.code
        task_action.action_code = cur_station_no
        task_action.action = cur_station_name
        task_action.eq_code = "system"
        task_action.eq_type_name = cur_station_name
        nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, task_action)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '创建【任务动作】对象失败!' .. strRetInfo) end
 
        -- V2.0 LZH 新增类型8 入库重量上报
    elseif (feed_type == 8) then
        lua.Debug(strLuaDEID, debug.getinfo(1), 'task:', task)
        lua.Debug(strLuaDEID, debug.getinfo(1), '国自任务反馈参数:', in_date)
        -- 获取容器货品明细信息
        local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
        local cg_detail
        nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", strCondition)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '获取容器货品信息失败!' .. cg_detail) end
 
        -- 修改入库单据行的称重数量信息
        strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
        local strSetAttr = "S_WEIGHT = '" .. weight .. "'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Label_Crad", strCondition, strSetAttr)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "更新【容器】锁状态失败!" .. strRetInfo) end
    end
end