--[[
|
编码: GT-100-03
|
名称: GT-WMS
|
作者:LZH
|
入口函数: MaterialMaintain
|
|
|
功能说明:
|
GT-WMS下发基础物料信息给 GZ-WMS系统,GZ-WMS系统对基础数据进行新增/修改
|
|
输入数据:
|
[{
|
"item_code": "xxx", -- 物料编码
|
"item_name": "xxx", -- 物料描述
|
"is_validate": "Y", -- 是否条码验证
|
"sub_type": "粉料01", -- 中类
|
"minor_type": "粉料0102", --小类
|
"isothermal": "Y", -- 是否恒温
|
"is_insulate": "N", -- 是否保温
|
"is_pack": "N", -- 是否拣选
|
"wh_code": "AHYLK", -- 仓库号
|
"area_code": "全钢", -- 库区
|
"remark1": "", -- 备注 暂未启用
|
"remark2": "", -- 备注 暂未启用
|
"remark3": "", -- 备注 暂未启用
|
"remark4": "" -- 备注 暂未启用
|
},
|
...
|
]
|
|
处理逻辑
|
-- step1 解析接口传递的 datajson 参数
|
-- step2 校验必传字段是否为空,为空则报错
|
-- step3 根据接口类型字段对基础数据进行新增或修改操作
|
|
变更记录:
|
20241111 LZH V1.1 GT-WMS要求格式为List
|
20250221 LZH V1.2 新增4个备用字段
|
--]]
|
m3 = require("oi_base_mobox")
|
json = require("json")
|
mobox = require("OILua_JavelinExt")
|
function MaterialMaintain(strLuaDEID)
|
local nRet, strRetInfo, in_date, material
|
-- step1 获取接口数据
|
local list
|
nRet, list = m3.GetSysDataJson(strLuaDEID)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WCStoreCallback 无法获取数据包!" .. list) end
|
local count = #list
|
if (list == nil or count == 0) then return end
|
lua.Debug(strLuaDEID, debug.getinfo(1), '物料基础属性下发参数:', list)
|
|
for i = 1, count do
|
in_date = list[i]
|
-- step2 判断是否都有值?没值报错返回
|
local item_code = in_date.item_code
|
if (item_code == nil or item_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "物料编码不能为空!") end
|
local wh_code = in_date.wh_code
|
local sub_type = in_date.sub_type
|
local item_name = in_date.item_name
|
local is_validate = in_date.is_validate
|
local minor_type = in_date.minor_type
|
local isothermal = in_date.isothermal
|
local is_pack = in_date.is_pack
|
local area_code = in_date.area_code
|
-- V1.2 新增备用字段
|
local remark1 = in_date.remark1
|
local remark2 = in_date.remark2
|
local remark3 = in_date.remark3
|
local remark4 = in_date.remark4
|
|
local strSetSQL_update = ""
|
-- 拼接修改语句
|
if (wh_code ~= nil and wh_code ~= '') then
|
strSetSQL_update = strSetSQL_update .. ",S_WH_CODE = '" .. wh_code .. "'"
|
end
|
if (item_name ~= nil and item_name ~= '') then
|
strSetSQL_update = strSetSQL_update .. ",S_ITEM_NAME = '" .. item_name .. "'"
|
end
|
if (is_validate ~= nil and is_validate ~= '') then
|
strSetSQL_update = strSetSQL_update .. ",C_IS_VALIDATE = '" .. is_validate .. "'"
|
end
|
if (sub_type ~= nil and sub_type ~= '') then
|
strSetSQL_update = strSetSQL_update .. ",S_SUB_TYPE = '" .. sub_type .. "'"
|
end
|
if (minor_type ~= nil and minor_type ~= '') then
|
strSetSQL_update = strSetSQL_update .. ",S_MINOR_TYPE = '" .. minor_type .. "'"
|
end
|
if (isothermal ~= nil and isothermal ~= '') then
|
strSetSQL_update = strSetSQL_update .. ",C_IS_ISOTHERMAL = '" .. isothermal .. "'"
|
end
|
if (is_pack ~= nil and is_pack ~= '') then
|
strSetSQL_update = strSetSQL_update .. ",C_IS_PACK = '" .. is_pack .. "'"
|
end
|
if (area_code ~= nil and area_code ~= '') then
|
strSetSQL_update = strSetSQL_update .. ",S_AREA_CODE = '" .. area_code .. "'"
|
end
|
|
-- 判断修改语句是否为空,为空则不做操作,不为空则删除拼接语句的第一个 逗号字符并修改
|
if (strSetSQL_update ~= "") then
|
strSetSQL_update = strSetSQL_update:sub(2)
|
local strCondition = "S_ITEM_CODE = '" .. item_code .. "'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Material", strCondition,
|
strSetSQL_update)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改【物料】信息失败!" .. strRetInfo) end
|
if (tonumber(strRetInfo) == 0) then
|
-- step3 获取一个初始的【物料】数据对象
|
material = m3.AllocObject(strLuaDEID, "Material")
|
material.item_code = item_code
|
material.wh_code = wh_code
|
material.item_name = item_name
|
material.is_validate = is_validate
|
material.sub_type = sub_type
|
material.minor_type = minor_type
|
material.isothermal = isothermal
|
material.is_pack = is_pack
|
material.area_code = area_code
|
nRet, material = m3.CreateDataObj(strLuaDEID, material)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【物料】对象失败!' .. material) end
|
end
|
end
|
end
|
end
|