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
--[[
 编码: GT-100-15
 名称: 叠盘机空工装返回
 作者: LZH
 入口函数:EmptyCntrReturn
 功能说明: 获取物料号,如果为空则代表AGV在请求空叠盘机回库任务
    输入数据:                                                                                        
    {
    "partNumber": "物料号",
    "qty": null,
    "locationCode": "起点位置编码"
    "CntrCode":"容器号"
    }
 
    处理逻辑
    -- step1 解析接口传递的 datajson 参数
    -- step2 校验必传字段是否为空,为空则报错
    -- step3 重新计算终点货位
 变更历史:
 --]]
-- require("WMS-Equipment")
wms_cntr = require("wms_container")
wms_wh = require("wms_wh")
require("GT-Base")
function EmptyCntrReturn(strLuaDEID)
    local nRet, in_date
    -- step1 获取接口数据
    nRet, in_date = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WCStoreCallback 无法获取数据包!" .. in_date) end
    lua.Debug(strLuaDEID, debug.getinfo(1), '空工装返回参数:', in_date)
 
    -- step2 判断 必填项 是否都有值?没值报错返回
    local partNumber = in_date.partNumber     -- 物料号
    local locationCode = in_date.locationCode -- 起点位置
    local qty = tonumber(in_date.qty)         -- 数量
    local CntrCode = in_date.CntrCode         -- 容器号 多个用,号
    if (locationCode == nil or locationCode == '') then lua.Error(strLuaDEID, debug.getinfo(1), "起点不能为空!") end
 
    -- AGV请求叠盘机空托回库任务,WMS生成任务并下发的期间会重复请求,以第一次请求为准,根据起点判断是否已经生成任务
    -- 根据起点获取空托回库的任务
    local localtion
    local strCondition = "S_B_STATE IN ('等待','执行') AND S_START_LOC = '" ..
        locationCode .. "' AND S_OP_DEF_NAME = 'AGV空托回库'"
    nRet, localtion = m3.GetDataObjByCondition(strLuaDEID, "Operation", strCondition)
    if (nRet == 1) then
        -- 物料 = 空 代表AGV在请求我们叠盘机空托回库任务
        if (partNumber == nil or partNumber == '') then
            -- 绑定空托物料
            local cg_detail = m3.AllocObject(strLuaDEID, "CG_Detail")
            cg_detail.cntr_code = CntrCode
            cg_detail.item_code = "KGZ"
            cg_detail.item_name = "空工装"
            cg_detail.qty = qty
            cg_detail.uom = '个'
            nRet, cg_detail = m3.CreateDataObj(strLuaDEID, cg_detail)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '创建【容器货品明细】对象失败!' .. cg_detail) end
 
            -- 获取起点信息
            local loc_start
            nRet, loc_start = wms_wh.Location_GetInfo(strLuaDEID, locationCode)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo失败! " .. loc_start) end
 
            -- 创建空托盘组回库任务 一段任务agv搬运,二段任务国自搬运
            local operation           = m3.AllocObject(strLuaDEID, "Operation")
            -- 起点信息
            operation.start_wh_code   = loc_start.wh_code
            operation.start_area_code = loc_start.area_code
            operation.start_loc_code  = loc_start.code
 
            operation.cntr_code       = CntrCode
 
            operation.op_type         = wms_base.Get_nConst(strLuaDEID, "作业类型-入库")
            operation.op_def_name     = "AGV空托回库"
 
            nRet, operation           = m3.CreateDataObj(strLuaDEID, operation)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '创建【作业】失败!' .. operation) end
        else
            lua.Error(strLuaDEID, debug.getinfo(1), "未定义的流程! ")
        end
    elseif (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "获取【作业】信息失败! " .. localtion)
    end
end