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
--[[
 编码:
 名称: LocStateFeedBack
 作者:
 入口函数:LocStateFeedBack
 功能说明:
 变更历史:
 --]]
require("WMS-Equipment")
wms_cntr = require("wms_container")
wms_wh = require("wms_wh")
require("GT-Base")
require("GT_InAndOutboundPolicies")
function LocStateFeedBack(strLuaDEID)
    local nRet, in_date, strRetInfo
    -- step1 获取接口数据
    nRet, in_date = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "无法获取数据包!" .. in_date) end
    lua.Debug(strLuaDEID, debug.getinfo(1), '参数:', in_date)
 
    -- step2 判断 必填项 是否都有值?没值报错返回
    local loc_code = in_date.loc_code              -- 货位
    local type = lua.StrToNumber(in_date.type)     -- 1 允许取货 2 允许放货 3 取货完成允许离开 4 放货完成允许离开
    local req_no = lua.StrToNumber(in_date.req_no) -- 唯一码
    if (loc_code == nil or loc_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "站点不能为空!") end
    if (type == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "类型不能为空!") end
 
    -- 根据WCS站点获取货位
    loc_code = wms_base.Get_sConst(strLuaDEID, loc_code)
 
    -- 根据类型和站点 获取对应的AGV任务
    local task_no
    if (type == 1 or type == 3) then
        -- 站点为起点,任务状态为已推送
        local condition = "S_START_LOC = '" ..
        loc_code ..
        "' AND N_B_STATE = 1 AND S_CODE IN (SELECT S_TASK_CODE FROM TN_Task_Action WHERE N_ACTION_CODE = " .. type .. ")"
        nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Task", condition, "T_CREATE")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取【任务】信息失败! " .. strRetInfo) end
        task_no = strRetInfo.code
    elseif (type == 2) then
        -- 站点为终点,任务状态为已推送
        local condition = "S_END_LOC = '" ..
        loc_code ..
        "' AND N_B_STATE = 1 AND S_CODE IN (SELECT S_TASK_CODE FROM TN_Task_Action WHERE N_ACTION_CODE = " .. type .. ")"
        nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Task", condition, "T_CREATE")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取【任务】信息失败! " .. strRetInfo) end
        task_no = strRetInfo.code
    elseif (type == 4) then
        -- 站点为终点,任务状态为已推送
        local condition = "S_END_LOC = '" ..
        loc_code .. "' AND S_CODE IN (SELECT S_TASK_CODE FROM TN_Task_Action WHERE N_ACTION_CODE = " .. type .. ")"
        nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Task", condition, "T_CREATE")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取【任务】信息失败! " .. strRetInfo) end
        if (strRetInfo.op_name == '退料入库' or strRetInfo.op_name == 'AGV空托回库') then
            -- 解锁货位
            nRet, strRetInfo = wms.wms_UnlockByTask(strLuaDEID, loc_code)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_UnlockByTask 失败! " .. strRetInfo) end
        end
    else
        lua.Error(strLuaDEID, debug.getinfo(1), "未定义的状态反馈类型!")
    end
 
    -- 调用AGV的安全交互接口
    local url = wms_base.Get_sConst(strLuaDEID, "AGV-url")
    local strurl = url .. "/AllowThrough"
    local strHeader = ""
    local data = {
        task_no = task_no,
        type = type, -- 1 允许取货 2 允许放货 3 取货完成允许离开 4 放货完成允许离开
        loc = loc_code,
        req_no = req_no
    }
    nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, data, "AGV", "货位状态反馈")
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "调用接口失败!" .. strRetInfo)
    end
end