1
Jianw
9 天以前 70f29da38121b9a467841253e3268feb5df02902
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
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by HUI.
--- DateTime: 2024/3/7 9:58
---
 
require("WMS-WHAreaLoc")
require("oi_basestrfunc")
json = require("json")
mobox = require("OILua_JavelinExt")
 
function ClippingOutStock (strLuaDEID)
 
    local nRet, strRetInfo, resData
 
    -- 获取勾选的信息
    nRet, strRetInfo = mobox.getCurEditDataPacket(strLuaDEID)
    if (nRet ~= 0) then
        Error(strLuaDEID, debug.getinfo(1), "调用getCurEditDataPacket接口出错" .. strRetInfo)
    end
    if (strRetInfo == "") then
        Error(strLuaDEID, debug.getinfo(1), "未获取到勾选信息")
    end
 
    Debug(strLuaDEID, debug.getinfo(1), "勾选的信息strRetInfo:", strRetInfo)
 
    resData = json.decode(strRetInfo)
 
    local cntr_code
    -- 获取容器编码
    for n = 1, #resData do
        local resAttrs = resData[n].attrs
        for m = 1, #resAttrs do
            local resAttr = resAttrs[m].attr
            local resValue = resAttrs[m].value
            if (resAttr == "S_CNTR_CODE") then
                cntr_code = resValue
                -- 根据容器编码查询所在货位编码
                local strTableName = "TN_Loc_Container"
                local strFieldList = '["S_LOC_CODE"]'
                local nRetCount = 10
                local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
                local strOrderBy = ""
                nRet, strRetInfo = mobox.queryTable(strLuaDEID, strTableName, strFieldList, nRetCount, strCondition, strOrderBy)
                if (nRet ~= 0) then
                    Error(strLuaDEID, debug.getinfo(1), "调用queryTable接口出错" .. strRetInfo)
                end
                if (strRetInfo == "") then
                    Error(strLuaDEID, debug.getinfo(1), "未获取到勾选信息")
                end
                Debug(strLuaDEID, debug.getinfo(1), "根据容器编码查询到的货位信息strRetInfo:", strRetInfo)
                local loc_info = json.decode(strRetInfo)
                for i = 1, #loc_info do
                    local start_bit = loc_info[i].S_LOC_CODE
                    -- 判断起点有没有非完成或者非错误的作业, 有则跳过循环, 不进行创建
                    local strTabName = 'TN_Operation'
                    local strCondition1 = "S_START_LOC = '" .. start_bit .. "' AND N_B_STATE NOT IN ('" .. WMS_nConst(strLuaDEID, "作业状态-完成") .. "', '" .. WMS_nConst(strLuaDEID, "作业状态-错误") .. "')"
                    -- 获取满足条件的任务条数
                    nRet, strRetInfo = mobox.getDBRecordCount(strLuaDEID, strTabName, strCondition1)
                    if (nRet ~= 0) then
                        Error(strLuaDEID, debug.getinfo(1), "调用接口getDBRecordCount获取数据失败" .. strRetInfo)
                    end
                    -- 有未完成的作业
                    if (strRetInfo ~= "0") then
                        Debug(strLuaDEID, debug.getinfo(1), "根据容器编码" .. cntr_code .. "查询到的货位创建作业失败, 当前位置有未完成的作业", loc_code)
                    else
                        -- 没有未完成的作业
                        -- 获取起点货位信息
                        local location_start
                        nRet, location_start = WMS_Location_GetInfo(strLuaDEID, start_bit)
                        if (nRet ~= 0) then
                            Error(strLuaDEID, debug.getinfo(1), 'WMS_Location_GetInfo获取起点货位信息失败!' .. location_start)
                        end
                        if (strRetInfo == "") then
                            Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo获取起点货位信息为空")
                        end
 
                        -- 根据起点获取起点所在库区,再确定出库口
                        local end_bit
                        local start_area_code = location_start.area_code
                        if (start_area_code == "AF1-01") then
                            end_bit = "LL1-1001"
                        elseif (start_area_code == "AF2-01") then
                            end_bit = "LL2-1001"
                        elseif (start_area_code == "AF3-01") then
                            end_bit = "LL3-1060"
                        elseif (start_area_code == "AF4-01") then
                            end_bit = "LL4-1064"
                        elseif (start_area_code == "AF5-01") then
                            end_bit = "LL5-1068"
                        end
 
                        -- 获取终点货位信息
                        local location_end
                        nRet, location_end = WMS_Location_GetInfo(strLuaDEID, end_bit)
                        if (nRet ~= 0) then
                            Error(strLuaDEID, debug.getinfo(1), 'WMS_Location_GetInfo获取终点货位信息失败!' .. location_end)
                        end
                        if (strRetInfo == "") then
                            Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo获取终点货位信息为空")
                        end
 
                        -- 创建作业
                        local operation = AllocObject(strLuaDEID, "Operation")
                        operation.start_wh_code = location_start.wh_code
                        operation.start_area_code = location_start.area_code
                        operation.start_loc_code = location_start.code
                        operation.end_wh_code = location_end.wh_code
                        operation.end_area_code = location_end.area_code
                        operation.end_loc_code = location_end.code
                        operation.op_type = WMS_nConst(strLuaDEID, "作业类型-出库")
                        operation.op_def_code = "OP014"
                        operation.op_def_name = "剪版出库"
                        operation.cntr_code = cntr_code
 
                        Debug(strLuaDEID, debug.getinfo(1), "作业创建前:", operation)
 
                        nRet, strRetInfo = CreateDataObj(strLuaDEID, operation)
                        if (nRet ~= 0) then
                            Error(strLuaDEID, debug.getinfo(1), '创建【作业】失败!' .. strRetInfo)
                        end
                    end
                end
            end
        end
    end
end