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
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
--[[
    编码: JX-108-18
    名称: 巨星任务-创建巨星出库作业
    作者:HAN  
    日期:2025-1-29
 
    级别:项目
    
    函数: CreateOutOperation
 
    功能:
        根据巨星下发的出库任务创建巨星出库作业
        -- 如果已经指定 end_loc 直接出库到这个位置,没有需要根据 终点区域分配一个货位
 
    更改记录:
 
--]]
jx_base= require( "jx_base" )
wms_alg = require( "wms_base_algorithm" )
 
function CreateOutOperation ( strLuaDEID ) 
    local nRet, strRetInfo
    local strUpdateSql, strCondition
    local jx_task = {}
    nRet, jx_task = m3.GetSysCurEditDataObj( strLuaDEID, "JX_Task" )
    if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "获取【巨星任务】对象属性失败!"..jx_task ) end
    
    -- 获取作业起点
    local start_loc, loc_code
    local end_loc    
    local err_msg = ''
    loc_code = wms_wh.GetLocCodeByCNTR( strLuaDEID, jx_task.cntr_code )
    if ( loc_code == '' ) then
        err_msg = '料箱没有绑定货位!'
        goto err_msg_process
    end
    nRet, start_loc = wms_wh.GetLocInfo( loc_code )
    if ( nRet ~= 0 ) then 
        err_msg = "获取货位'"..loc_code.."'信息失败!"
        goto err_msg_process
    end             
 
    -- 获取作业终点
    if ( jx_task.end_loc_code ~= '') then
        -- 接口已经确定了出库目标货位
        nRet, end_loc = wms_wh.GetLocInfo( jx_task.end_loc_code )
        if ( nRet ~= 0 ) then 
            err_msg = "获取货位'"..jx_task.end_loc_code.."'信息失败!"
            goto err_msg_process
        end                       
    else
        -- 接口确定了出库区域
        if ( jx_task.end_area_code == '' ) then
            err_msg = "出库任务没有指定出库目的库区"
            goto err_msg_process
        end
        local loc_list
        nRet, loc_list = wms_alg.GetAreaLocTaskNumber( strLuaDEID, jx_task.end_area_code )
        if ( nRet ~= 0 ) then
            err_msg = "获取出库终点货位失败!"..loc_list
            goto err_msg_process
        end
        nRet, end_loc = wms_wh.GetLocInfo( loc_list[1].loc_code )
        if ( nRet ~= 0 ) then 
            err_msg = "获取货位'"..loc_list[1].loc_code.."'信息失败!"
            goto err_msg_process
        end           
 
    end
 
    operation = m3.AllocObject(strLuaDEID,"Operation")
    operation.start_wh_code = start_loc.wh_code
    operation.start_area_code = start_loc.area_code
    operation.start_loc_code = start_loc.code
 
    operation.end_wh_code = end_loc.wh_code
    operation.end_area_code = end_loc.area_code
    operation.end_loc_code = end_loc.code
 
    operation.cntr_code = jx_task.cntr_code
 
    operation.op_type = wms_base.Get_nConst(strLuaDEID, "作业类型-出库")
    operation.op_def_name = "巨星出库"
    operation.bs_type = "巨星任务"
    operation.bs_no = jx_task.sour_no
    operation.source_sys = "巨星"
    nRet, operation = m3.CreateDataObj( strLuaDEID, operation )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '创建【作业】失败!'..operation ) end  
    
    -- N_B_STATE = 1 任务执行
    strUpdateSql = "N_B_STATE = 1, 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  
    
    ::err_msg_process::
    -- 4 表示任务执行失败
    if ( err_msg ~= '' ) then
        strUpdateSql = "N_B_STATE = 4, S_RUN_ERR = '"..lua.FormatSQLString(err_msg).."'"
        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  
    end
end