Jianw
2025-05-13 3b39fe3810c3ee2ec9ec97236c1769c5c85e062c
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
--[[
    编码: JX-108-17
    名称: 巨星任务-巨沃空料箱入库
    作者:HAN  
    日期:2025-1-29
 
    级别:项目
    
    函数: ClickRun
 
    功能:
        -- 巨沃料箱初始化操作的一部分
        -- 创建‘巨沃空料箱入库’作业
 
    更改记录:
 
--]]
jx_base= require( "jx_base" )
wms_cntr= require( "wms_container" )
wms_wh = require( "wms_wh" )
 
function ClickRun ( strLuaDEID ) 
    local nRet, strRetInfo
 
    local strUserLogin, strUserName
    nRet, strUserLogin, strUserName = mobox.getCurUserInfo( strLuaDEID )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前操作人员信息失败! "..strUserLogin ) end
 
    -- 获取TOPVIEW的输入信息
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_STATION_NO","S_CNTR_CODE","BoxCellNum" ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end 
    local obj_attrs = json.decode( strRetInfo ) 
    local station = lua.Get_StrAttrValue( obj_attrs[1].value )  
    local cntr_code = lua.Get_StrAttrValue( obj_attrs[2].value ) 
    local box_cell_num = lua.Get_NumAttrValue( obj_attrs[3].value )  -- 料格数量
    local cell_spec = {"A","B","C","D","","E"}
 
    if ( station == '' or cntr_code == '' or box_cell_num <= 0 or box_cell_num > 6 )  then 
        mobox.setInfo( strLuaDEID, "输入参数不完整,无法执行入库作业!")
        return 
    end
 
    -- 检查一下空料箱是否存在,不存在创建
    local cntr
    nRet, cntr = wms_cntr.GetInfo( strLuaDEID, cntr_code )
    if ( nRet ~= 0 ) then
        lua.Error( strLuaDEID, debug.getinfo(1), "获取容器信息失败!"..cntr)
    end     
    if  ( cntr == '' ) then
        -- 没有这个容器系统创建一个容器
        cntr = m3.AllocObject( strLuaDEID, "Container" )
        cntr.code = cntr_code
        cntr.type = 3           -- 巨星料箱
        cntr.spec = cell_spec[box_cell_num]
        nRet, container = m3.CreateDataObj(strLuaDEID, cntr)
        if (nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1),"创建【容器】失败!"..container ) end           
    else
        if ( cntr.type ~= 3 ) then
            mobox.setInfo( strLuaDEID, "料箱'"..cntr_code.."'的类型不正确, 巨沃空料箱入库的料箱必须是料格类型!")
            return             
        end 
        -- 判断一下容器是否已经和货位绑定,有不能做空料箱入库
        local loc_code = wms_wh.GetLocCodeByCNTR( strLuaDEID, cntr_code )
        if ( loc_code ~= '') then
            mobox.setInfo( strLuaDEID, "料箱'"..cntr_code.."'的已经和货位'"..loc_code.."'绑定,不能做空料箱入库操作!")
            return              
        end
        if ( cntr.empty_full ~= 0 ) then
            mobox.setInfo( strLuaDEID, "料箱'"..cntr_code.."'不是空料箱,不能做空料箱入库操作!")
            return              
        end
    end
 
    -- 获取站点货位,站点货位定义在常量中
    local loc_code = jx_base.Get_Station_Loc( strLuaDEID, station )
    local loc
    nRet, loc = wms_wh.GetLocInfo( loc_code )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '获取货位信息失败! '..loc_code ) end  
 
    -- 创建一个【巨星任务】,类型(入库)
    local jx_task = m3.AllocObject(strLuaDEID,"JX_Task")
    jx_task.task_type = "巨沃空料箱入库"
    jx_task.b_state = 1                     -- 作业启动
    jx_task.station = station
    jx_task.start_wh_code = loc.wh_code
    jx_task.start_area_code = loc.area_code
    jx_task.start_loc_code = loc_code
    jx_task.cntr_code = cntr_code
    jx_task.operator_name = strUserName
    jx_task.operator = strUserLogin
    nRet, jx_task = m3.CreateDataObj( strLuaDEID, jx_task )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '创建【巨星任务】失败!'..jx_task ) end 
 
    local operation
    local ext_info = {}
    ext_info.bs_type = "巨星任务"
    ext_info.bs_no = jx_task.sour_no
    nRet, operation = jx_base.Create_StorageOperation( strLuaDEID, "巨沃", station, cntr_code, "巨沃入库", ext_info )
    if ( nRet ~= 0 ) then
        mobox.setInfo( strLuaDEID, operation )
        return
    end 
 
    strUpdateSql = "S_OP_CODE = '"..operation.code.."'"
    strCondition = "S_SOURNO = '"..jx_task.sour_no.."'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "JX_Task", strCondition, strUpdateSql )
    if ( nRet ~= 0 ) then  lua.Error( strLuaDEID, debug.getinfo(1), "更新【巨星任务】信息失败!"..strRetInfo ) end   
     
    mobox.setInfo( strLuaDEID, "系统已经成功创建了一个巨沃空料箱入库作业'"..operation.code.."'")
    local action = 
    {
        {
            action_type = "refresh",
            value = ""   
        }
    }
 
    nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action)  )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo ) end 
 
    -- 【注意】如果上面的程序有入库作业产生需要对入库作业的终点获取加入库锁
    nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, operation.end_loc_code, wms_base.Get_nConst( strLuaDEID, "锁类型-入库锁" ),
                                            "", operation.code, operation.op_def_name )
    if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "wms_LockLocation 失败!"..strRetInfo ) end        
end