案例中心 视频中心

Mobox低代码平台- 主类及子类数据导入实现 Mobox低代码平台- 主类及子类数据导入实现

Mobox低代码平台- 主类及子类数据导入实现

我们在巨星工艺系统里面遇到,用户需要将产品工艺一次性导入的需求

软件系统架构图:

数据对象介绍

产品及工艺导入,我们提供了一个excel模板

定义导入脚本(自定义脚本)

–[[

    编码: CappImport

    名称: 产品及工艺信息导入

    作者:whx   

    入口函数:ImportCapp

 

    功能说明:

        产品及工艺的导入,在导入的时候判断一下产品是否存在?如果不存在要新创建

        导入格式见《产品-工艺-导入test.xlsx》

    变更历史:

        V1.0  whx    2023-4-12      新建

 

    数据结构说明

         产品

                   工艺1

                   工艺2

                   工艺…

         其中,有数据对象《产品》 子类 《工艺》 (S_GDS_CODE 为关联字段)

         使用前,将2个对象的所有字段 对应的变量都定义一下  《参考代码里面的  产品字段对应变量定义;工艺字段对应变量定义》

–]]

 

json  = require(“json”)

mobox = require(“OILua_JavelinExt”)

require(“oi_basestrfunc”)

 

function ImportCapp(strLuaDEID)

    local nRet, strRetInfo

    — 获取导入的数据, 返回 [{“attr”:”xx”,”value”:””},…]

   

    nRet, strRetInfo = mobox.getInputParameter(strLuaDEID)

    –mobox.writeSysLog(“nRet”,nRet)

 

    if (nRet ~= 0 or strRetInfo == ”) then

        mobox.error(strLuaDEID, “无法获取导入数据!”)

        return

    end

    –mobox.writeSysLog(“strRetInfo”,strRetInfo)

    local retJson = json.decode(strRetInfo)

   

    local input = retJson[“parameter”]

   

    local n, nCount, nValue

    local strAddAttr = ”

 

    — 产品字段对应变量定义

    local strGDSCode = ”

 

    local strGDSName = ”

    local strGDSClass = ”

    local strGDSSeries = ”

    local strGDSSpec = ”

    local strGDSDescribe = ”

 

    — 工艺字段对应变量定义

    local strMPName = ”

    local strMPCode = ”

    local strMPDescrive = ”

    local strN_On = ”

 

    — 步骤1 获取从excel导入的一行数据,根据excel的产品规格定义进行属性组合 strAddAttr

    nCount = #input

    for n = 1, nCount do

        strAttr = input[n].attr

        strValue = input[n].value

        if (strAttr ~= ” and strValue ~= ”) then

 

            — 根据导入的excel产品规格头名称进行判断

            — 关键属性判断

            if (strAttr == “产品编码”) then

                if (strValue == ”) then

                    mobox.error(strLuaDEID, strAttr .. “不能为空!”)

                    return

                end

                strGDSCode = strValue

                strAddAttr = strAddAttr .. ‘{“attr”:”S_GDS_CODE”,”value”:”‘ .. strGDSCode .. ‘”},’

 

            elseif (strAttr == “产品名称”) then

                if (strValue == ”) then

                    mobox.error(strLuaDEID, strAttr .. “不能为空!”)

                    return

                end

                strGDSName = strValue

                strAddAttr = strAddAttr .. ‘{“attr”:”S_GDS_NAME”,”value”:”‘ .. strGDSName .. ‘”},’

 

            elseif (strAttr == “过程名称”) then

                if (strValue == ”) then

                    mobox.error(strLuaDEID, strAttr .. “不能为空!”)

                    return

                end

                strMPName = strValue

                strAddAttr = strAddAttr .. ‘{“attr”:”S_MP_NAME”,”value”:”‘ .. strMPName .. ‘”},’

               

            elseif (strAttr == “过程编号”) then

                if (strValue == ”) then

                    mobox.error(strLuaDEID, strAttr .. “不能为空!”)

                    return

                end

                strMPCode = strValue

                strAddAttr = strAddAttr .. ‘{“attr”:”S_MP_CODE”,”value”:”‘ .. strMPCode .. ‘”},’

               

            — 常规属性

 

            elseif (strAttr == “产品分类”) then

                strGDSClass = strValue

                strAddAttr = strAddAttr .. ‘{“attr”:”S_GDS_CLASS”,”value”:”‘ .. strGDSClass .. ‘”},’

 

            elseif (strAttr == “产品系列”) then

                strGDSSeries = strValue

                strAddAttr = strAddAttr .. ‘{“attr”:”S_GDS_SERIES”,”value”:”‘ .. strGDSSeries .. ‘”},’

 

            elseif (strAttr == “产品规格”) then

                strGDSSpec = strValue

                strAddAttr = strAddAttr .. ‘{“attr”:”S_GDS_SPEC”,”value”:”‘ .. strGDSSpec .. ‘”},’

 

            elseif (strAttr == “产品描述”) then

                strGDSDescribe = strValue

                strAddAttr = strAddAttr .. ‘{“attr”:”S_GDS_DESCRIBE”,”value”:”‘ .. strGDSDescribe .. ‘”},’

 

            elseif (strAttr == “序号”) then

                strN_On = strValue

                strAddAttr = strAddAttr .. ‘{“attr”:”N_ON”,”value”:”‘ .. strN_On .. ‘”},’

 

            elseif (strAttr == “过程描述”) then

                strMPDescrive = strValue

                strAddAttr = strAddAttr .. ‘{“attr”:”S_MP_DESCRIBE”,”value”:”‘ .. strMPDescrive .. ‘”},’

            end

        end

 

    end

    –去除最后一个,

    local strAddAttr1 = trim_laster_char(strAddAttr)

 

    — 步骤2 根据(产品编码 + 过程名称) 来判断导入的工艺步骤是否已经存在

    —       如果已经存在,根据导入的数据进行覆盖

    —       如果不存在需要创建

    local attrs

    local strCondition = “S_GDS_CODE='” .. strGDSCode .. “‘ and S_MP_NAME = ‘” .. strMPName .. “‘ “

    nRet, strRetInfo = mobox.existThisData(strLuaDEID, “工艺”, strCondition)

    if (nRet ~= 0) then

        mobox.error(strLuaDEID, “在检查工艺是否存在时失败! ” .. strRetInfo)

        return

    end

 

    if (strRetInfo == ‘yes’) then

        — 已经存在,根据导入的数据进行覆盖

        strCondition = “S_GDS_CODE='” .. strGDSCode .. “‘ and S_MP_NAME = ‘” .. strMPName .. “‘ “

 

        strSetSQL = “S_GDS_CODE = ‘” ..strGDSCode ..”‘ , S_MP_DESCRIBE ='” ..strMPDescrive ..

            “‘ , S_MP_NAME = ‘” .. strMPName .. “‘ , S_MP_CODE = ‘” .. strMPCode .. “‘ , N_ON = ‘” .. strN_On ..”‘ “

 

        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, “工艺”, strCondition, strSetSQL)

        if (nRet ~= 0) then

            mobox.error(strLuaDEID, strRetInfo)

            return

        end

        return

 

     elseif (strRetInfo == ‘no’) then

     — 新增工艺

         attrs = ‘[{“attr”:”S_GDS_CODE”,”value”:”‘ .. strGDSCode .. ‘”},’

         .. ‘{“attr”:”S_MP_NAME”,”value”:”‘ .. strMPName .. ‘”},’

         .. ‘{“attr”:”N_ON”,”value”:”‘ .. strN_On .. ‘”},’

         .. ‘{“attr”:”S_MP_CODE”,”value”:”‘ .. strMPCode .. ‘”},’

         .. ‘{“attr”:”S_MP_DESCRIBE”,”value”:”‘ ..  strMPDescrive .. ‘”}]’

 

    — mobox.writeSysLog(“attrs”,attrs)

   

         nRet, strRetInfo = mobox.createDataObj(strLuaDEID, “工艺”, attrs)

         if (nRet ~= 0) then

                   mobox.error(strLuaDEID, “创建工艺失败! ” .. strRetInfo)

                   return

         end

 

          — 导入的工艺不存在的时候,就需要判断一下 产品是否存在

         — 如果不存在需要创建

         — 判断产品是否存在

         strCondition = “S_GDS_CODE='” .. strGDSCode .. “‘”

         nRet, strRetInfo = mobox.existThisData(strLuaDEID, “产品”, strCondition)

         if (nRet ~= 0) then

                   mobox.error(strLuaDEID, “在检查产品是否存在时失败! ” .. strRetInfo)

                   return

         end

 

         if (strRetInfo == ‘no’) then

         — 新增产品

 

                   attrs = ‘[{“attr”:”S_GDS_CODE”,”value”:”‘ .. strGDSCode .. ‘”},’

                   .. ‘{“attr”:”S_GDS_NAME”,”value”:”‘ .. strGDSName .. ‘”},’

                   .. ‘{“attr”:”S_GDS_CLASS”,”value”:”‘ .. strGDSClass .. ‘”},’

                   .. ‘{“attr”:”S_GDS_SERIES”,”value”:”‘ .. strGDSSeries .. ‘”},’

                   .. ‘{“attr”:”S_GDS_SPEC”,”value”:”‘ .. strGDSSpec .. ‘”},’

                   .. ‘{“attr”:”S_GDS_DESCRIBE”,”value”:”‘ .. strGDSDescribe .. ‘”}]’

 

                   –mobox.writeSysLog(“attrs”,attrs)

                   nRet, strRetInfo = mobox.createDataObj(strLuaDEID, “产品”, attrs)

                   if (nRet ~= 0) then

                            mobox.error(strLuaDEID, “创建产品失败! ” .. strRetInfo)

                            return

                   end

     end

 

    end

 

end

定义导入命令

设置导入命令的相关参数

 

我们可以通过excel批量导入企业的工艺信息

标签:方案脚本 上一篇: 下一篇:
展开更多
预约软件体验

loading...