wsz
2025-06-20 19898bd66dec87b500b200d5d50961d0fb538ce5
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
--[[
    编码: WMS-40-01
    名称: 创建前
    作者:HAN  
    日期:2025-1-29
 
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: BeforeDataObjCreate
 
    功能:
        1)生成作业编码 S_OP_CODE, 格式:OP221212-00001
        2)赋值 S_OP_TYPE
    更改记录:
 
--]]
 
wms_base = require( "wms_base" )
 
function BeforeDataObjCreate ( strLuaDEID ) 
    local   nRet, strRetInfo
    -- step1  获取当前创建的作业信息 -- 作业类型,业务状态
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "N_TYPE","N_B_STATE" ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end 
    local obj_attrs = json.decode( strRetInfo ) 
    local op_type = lua.StrToNumber( obj_attrs[1].value )           -- 作业类型
    local b_state = lua.StrToNumber( obj_attrs[2].value )           -- 业务状态
 
    if ( b_state == "" ) then b_state = 1 end
    if ( op_type == "" ) then op_type = 0 end
    if ( op_type == 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "作业类型没有赋值! "..strRetInfo ) end
 
    -- 根据字典获取 N_TYPE 的显示名称
    -- 返回:[{"name":"xxx","order":"1","value":"yyy","default":"1","code":""},…]
    local str_op_type = wms_base.GetDictItemName( strLuaDEID, "WMS_OperationType", op_type ) 
 
    -- 根据字典获取 N_B_STATE 的显示名称
    local str_b_satte = wms_base.GetDictItemName( strLuaDEID, "WMS_OperationState", b_state ) 
 
    -- 生成作业编码
    local strCode = ''
    local strHeader = 'OP'..os.date("%y%m%d")..'-'
    nRet,strCode = mobox.getSerialNumber( "作业", strHeader, 5 )  
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '申请作业编码失败!'..strCode ) end
 
    -- 设置信息
    local   attr_value = {}
    attr_value[1] = lua.KeyValueObj( "S_B_STATE", str_b_satte )
    attr_value[2] = lua.KeyValueObj( "S_TYPE", str_op_type )
    attr_value[3] = lua.KeyValueObj( "S_CODE", strCode )
    nRet, strRetInfo = mobox.setCurEditDataObjAttr( strLuaDEID, lua.table2str(attr_value) ) 
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "设置作业信息失败!  "..strRetInfo ) end   
end