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
--[[
    编码: GT-40-37
    名称: 作业-立库入库-任务完成
    作者:LZH
    日期:2024-12-24
    版本: V1.0
    场景:作业中的任务完成后触发这个脚本
    函数: TaskFinish
    功能:
        -- 立库搬运入库任务完成即可认为作业完成
 
    更改记录:
 
--]]
wms_op = require("wms_operation")
wms_cntr = require("wms_container")
require("GT_InAndOutboundPolicies")
wms_op = require("wms_operation")
function TaskFinish(strLuaDEID)
    local nRet, strRetInfo
 
    local operation
    nRet, operation = m3.GetSysCurEditDataObj(strLuaDEID, "Operation")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), operation) end
 
    -- 获取任务对象
    local task
    nRet, task = m3.SysInputParamToDataObj(strLuaDEID, "Task")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), task) end
 
    -- 获取生成 作业时,保存在拓展字段里的天然胶字段
    local ext_data   = json.decode(operation.ext_data)
    local abnormal   = ext_data.abnormal
 
    nRet, strRetInfo = wms_op.SetFinish(strLuaDEID, operation.code)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "设置作业编号='" .. operation.code .. "' 的作业完成失败!" .. strRetInfo)
    end
 
    -- 获取容器货品明细
    local cg_detail
    local strCondition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'"
    nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!" .. cg_detail) end
 
    if (tonumber(cg_detail.is_fj) == 0) then
        -- 加库区/库量表 (通过CG_Detail)
        nRet = wms.wms_ResetInventory("Area", task.end_area_code)
 
 
        -- 获取入库单据行信息
        local label_crad
        strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
        nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition, "T_CREATE DESC")
        if (nRet == 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
        elseif (nRet > 1) then
            lua.Error(strLuaDEID, debug.getinfo(1), "获取入库单据行信息失败!" .. label_crad)
        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
 
        -- 如果入库单是手工录入的则
        if (incoming_Info.type == '手工录入') then
            -- 创建【GTWMS同步记录】
            local sys_record = m3.AllocObject(strLuaDEID, "GTWMS_SYNC_RECORD")
            sys_record.delivery_no = incoming_Info.delivery_no
            sys_record.delivery_row_no = incoming_Info.delivery_row_no
            sys_record.lpn = cg_detail.serial_no
            sys_record.rfid = operation.cntr_code
            sys_record.lpnweight = cg_detail.qty
            sys_record.sku = cg_detail.item_code
            sys_record.batch_no = cg_detail.batch_no
            sys_record.remark3 = cg_detail.serial_no
            sys_record.type = "入库回传"
            lua.Debug(strLuaDEID, debug.getinfo(1), 'sys_record', sys_record)
            nRet, sys_record = m3.CreateDataObj(strLuaDEID, sys_record)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【GTWMS同步记录】对象失败!' .. sys_record) end
        else
            -- 入库结果回传
            local data
            local source = "GTWMS入库回传"
            nRet, data = StorageResult(strLuaDEID, operation.code, source)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "入库结果回传失败!" .. data)
            end
            data.loc = "LK001"
            lua.Debug(strLuaDEID, debug.getinfo(1), 'data', data)
 
            -- 调用GT-WMS的回传接口
            local url = wms_base.Get_sConst(strLuaDEID, "GTWMS-url")
            local strurl = url
            local strHeader = ""
            local strBody = {
                application = "GITI",
                code = "WCS_ASN_WMS",
                data = data
            }
            nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "GTWMS", source)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "调用接口失败!" .. strRetInfo)
            end
        end
    else
        -- 修改容器货品明细的标识为复检出库
        local condition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'"
        local strSetSQL_update = "N_IS_FJ = 0"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "CG_Detail", condition, strSetSQL_update)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改容器货品明细失败!" .. strRetInfo) end
    end
 
    -- 如果是退料单则修改退料单状态为完成
    if (tonumber(cg_detail.is_tl) == 1) then
        local condition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'"
        local strSetAttr = "S_STATE = '完成'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_ROM", condition, strSetAttr)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "设置状态失败!" .. strRetInfo)
        end
    end
end