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
--[[
 编码: GT-40-44
 名称: 作业启动
 作者: LZH
 入口函数:OperationStart
 功能说明:
    创建一段AGV任务
 变更历史:
 --]]
require("GT-Base")
wms_op = require("wms_operation")
wms_wh = require("wms_wh")
wms_task = require("wms_task")
function OperationStart(strLuaDEID)
    local nRet, strRetInfo
    -- 获取作业对象, 从作业对象中获取{扩展数据}, 从{扩展数据}获取线体设备编码
    local operation
    nRet, operation = m3.GetSysCurEditDataObj(strLuaDEID, "Operation")
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "获取作业对象属性失败!" .. operation)
    end
 
    -- 判断作业里是否有明确容器,如果已经明确了容器说明出库的货品已经确定
    if (operation.cntr_code == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "作业中必须要有容器编号!")
    end
 
    -- 解析作业中的扩展参数
    local ext_data, success
    success, ext_data = pcall(json.decode, operation.ext_data)
    if (success == false) then
        lua.Error(strLuaDEID, debug.getinfo(1), "operation_obj.ext_data 中内容JSON格式不合法!")
    end
 
    -- 创建 AGV 搬运任务
    local task = m3.AllocObject(strLuaDEID, "Task")
    task.code = ext_data.task_no     -- 任务编码
    task.op_code = operation.code    -- 作业编码
    task.op_name = operation.op_def_name
    task.factory = operation.factory -- 工厂
    task.type = wms_base.Get_nConst(strLuaDEID, "任务类型-AGV入库搬运")
    task.cntr_code = operation.cntr_code
    -- 起点
    task.start_wh_code = operation.start_wh_code
    task.start_area_code = operation.start_area_code
    task.start_loc_code = operation.start_loc_code
    -- 终点
    task.end_wh_code = operation.end_wh_code
    task.end_area_code = operation.end_area_code
    task.end_loc_code = operation.end_loc_code
    task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-AGV") -- 设置调度类型
 
    lua.Debug(strLuaDEID, debug.getinfo(1), "任务创建前信息", task)
 
    nRet, task = m3.CreateDataObj(strLuaDEID, task)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "创建AGV入库任务失败!" .. task)
    end
 
    -- 通过容器获取物料信息
    local data = {}
    local cg_detail_list, cg_detail
    nRet, cg_detail_list = wms_cntr.Get_Container_Goods(strLuaDEID, task.cntr_code)
    nRet, cg_detail = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail_list[1].attrs))
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), cg_detail) end
 
    if (cg_detail.item_code ~= 'KGZ') then
        local label_crad
        local strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
        if (tonumber(cg_detail.is_tl) == 1) then
            nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_ROM", strCondition, "T_CREATE DESC")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取流水号信息失败!" .. label_crad) end
        else
            nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition, "T_CREATE DESC")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取流水号信息失败!" .. label_crad) end
        end
 
        -- 获取入库单据头信息
        local incoming_Info
        strCondition = "S_DELIVERY_NO = '" ..
            label_crad.delivery_no .. "' AND N_DELIVERY_ROW_NO = '" .. label_crad.delivery_row_no .. "'"
        nRet, incoming_Info = m3.GetDataObjByCondition(strLuaDEID, "GT_Incoming_Info", strCondition, "T_CREATE DESC")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取入库单据头信息失败!") end
 
        data = {
            taskData = {
                taskNum = task.code,
                pickStation = task.start_loc_code,
                dropStation = task.end_area_code,
                taskType = 5,
                carrierType = 1,
                priority = 1,
                wmsTaskNo = "",
                level = incoming_Info.level,
                produceTime = incoming_Info.product_date,
                tyreType = "",
                supplier = incoming_Info.vendor,
                receiveLot = cg_detail.batch_no,
                subpool = "",
                source = "YCL"
            },
            partData = {
                rfid = operation.cntr_code,
                lotNumber = nil,
                partNumber = cg_detail.item_code,
                partDesc = cg_detail.item_name,
                partType = nil,
                weight = cg_detail.qty,
                unit = cg_detail.wu,
                maturityTime = nil,
                productionTime = nil,
                stewingTime = nil,
                overdueTime = nil
            }
        }
    else
        data = {
            taskData = {
                taskNum = task.code,
                pickStation = task.start_loc_code,
                dropStation = task.end_area_code,
                taskType = 5, -- 点到库区类型
                carrierType = 1,
                priority = 1,
                wmsTaskNo = "",
                level = "",
                produceTime = "",
                tyreType = "",
                supplier = "",
                receiveLot = "",
                subpool = "",
                source = "YCL"
            },
            partData = {
                rfid = operation.cntr_code,
                lotNumber = nil,
                partNumber = "KT",
                partDesc = "空托",
                partType = nil,
                weight = cg_detail.qty,
                unit = cg_detail.wu,
                maturityTime = nil,
                productionTime = nil,
                stewingTime = nil,
                overdueTime = nil
            }
        }
    end
    -- 调用AGV任务下发
    local url = wms_base.Get_sConst(strLuaDEID, "AGV-url")
    local strurl = url .. "/CreateTask"
    local strHeader = ""
    local strBody = data
    nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "AGV", "任务创建")
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "调用接口失败!" .. strRetInfo)
    end
 
    -- 设置状态未推送
    wms_task.SetStateByCode(strLuaDEID, task.code, "任务状态-已推送")
end