1. 
        

          產品中心 業內新聞 案例中心 視頻中心

          Gungho任務二次開發-任務分類集成3000功能的擴展屬性excel導入 Gungho任務二次開發-任務分類集成3000功能的擴展屬性excel導入

          Gungho任務二次開發-任務分類集成3000功能的擴展屬性excel導入

          分類:二次開發 產品中心 518

          Gungho任務二次開發-任務分類集成3000功能的清單導入

          這個是一個標準的導入模板 ,使用前可以通過修改 表名,字段名稱,字段中文名,字段對應賦值變量名稱。

          –[[

          這個是一個標準的腳本,可以

          1、修改里面的數據對象名稱 樣品技術參數

          2、字段相關名稱(字段中文名、字段名稱、字段賦值變量名稱)

          字段名稱? ? ? ? ? ? ? ? ? ? ? ? ? ? 字段中文名? ? ? ? ? 字段對應賦值變量名

          N_SN? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?序號? ? ? ? ? ? ? ? ? ? ?nSN

          S_ITEM_NAME? ? ? ? ? ? ? ? ?名稱? ? ? ? ? ? ? ? ? ? ?strItemName

          S_ITEM_M_S_N? ? ? ? ? ? ? ?型號_規格_數量? ?strItemMSN

          S_ITEM_CODE? ? ? ? ? ? ? ? ?編號? ? ? ? ? ? ? ? ? ? ?strItemCode

          S_MANUFACTURER? ? ? ? 生產單位? ? ? ? ? ? ? strFacturer

          3、若字段不夠多,或太多,需要調整程序

          4、里面的唯一性判斷是 task_id + S_ITEM_NAME + S_ITEM_CODE (需要根據情況調整)

          –]]

          功能說明:json = require(“json”)

          mobox = require(“OILua_JavelinExt”)

          require(“oi_basestrfunc”)

          function ImportExcle(strLuaDEID)

          local nRet, strRetInfo

          local strPrjID = ”

          local strTaskID = ”

          — 獲取全局變量 prj_id, task_id

          nRet, strRetInfo = mobox.getGlobalAttr( strLuaDEID, “task_id”,”prj_id” )

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

          mobox.error( strLuaDEID, “系統無法獲取全局變量 “..strRetInfo )

          return

          end

          local input_paramter = json.decode( strRetInfo )

          strTaskID = input_paramter[1].value

          strPrjID = input_paramter[2].value

          if ( strTaskID == ” ) then

          mobox.error( strLuaDEID, “必須要有項目及任務相關信息” )

          return

          end

          — 獲取導入的單條數據, 返回 {“id”:”xxx”,”attrs”:[{“attr”:”attr1″,”value”:”xxx1″},{“attr”:”attr2″,”value”:”xxx2″}, …]}

          nRet, strRetInfo = mobox.getInputParameter(strLuaDEID)

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

          mobox.error(strLuaDEID, “無法獲取導入數據!”..strRetInfo)

          return

          end

          local n, nCount, nValue

          local strAddAttr = ”

          local strAttr = ”

          local strSetSQL = ”

          — 一些關鍵屬性 (腳本 后期只需要改字段名稱就可以)

          local nSN? ? ? ? ? ? ? ? ? ? ? ? ? ?— 對應 序號 N_SN

          local strItemName = ”? ? ? ? — 對應 名稱 S_ITEM_NAME

          local strItemMSN = ”? ? ? ? ?— 對應 型號_規格_數量 S_ITEM_M_S_N

          local strItemCode = ”? ? ? ? ?— 對應 編號 S_ITEM_CODE

          local strFacturer = ”? ? ? ? ? ? — 對應 生產單位 S_MANUFACTURER

           

          — 因為每次導入只傳一條記錄,所以當前條寫入 prj_id 及 task_id

          strAddAttr = strAddAttr .. ‘{“attr”:”G_TASK_ID”,”value”:”‘ .. strTaskID .. ‘”},’

          strAddAttr = strAddAttr .. ‘{“attr”:”G_PRJ_ID”,”value”:”‘ .. strPrjID .. ‘”},’

          local retJson =json.decode(strRetInfo)

          local input_rows =retJson[“parameter”]

          — 步驟1 獲取從excel導入的一行數據,根據excel的列定義進行屬性組合 strAddAttr

          nCount = #input_rows

          for n = 1, nCount do

          strAttr = input_rows[n].attr

          strValue = input_rows[n].value

          — 根據導入的excel列頭名稱進行判斷

          — 關鍵屬性判斷

          if (strAttr == “名稱”) then

          if (strValue == ”) then

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

          return

          end

          strItemName = strValue
          strAddAttr = strAddAttr .. ‘{“attr”:”S_ITEM_NAME”,”value”:”‘ .. strItemName .. ‘”},’

           

          — 常規屬性

          elseif (strAttr == “序號”) then

          nSN = strValue
          strAddAttr = strAddAttr .. ‘{“attr”:”N_SN”,”value”:”‘ .. nSN .. ‘”},’

          elseif (strAttr == “型號_規格_數量”) then

          strItemMSN = strValue
          strAddAttr = strAddAttr .. ‘{“attr”:”S_ITEM_M_S_N”,”value”:”‘ .. strItemMSN .. ‘”},’

          elseif (strAttr == “編 號”) then

          strItemCode= strValue
          strAddAttr = strAddAttr .. ‘{“attr”:”S_ITEM_CODE”,”value”:”‘ .. strItemCode .. ‘”},’

          elseif (strAttr == “生產廠家”) then

          strFacturer = strValue
          strAddAttr = strAddAttr .. ‘{“attr”:”S_MANUFACTURER”,”value”:”‘ .. strFacturer .. ‘”},’

          end

          end
          –去除最后一個,
          local strAddAttr1 = trim_laster_char(strAddAttr)

          — 步驟2 根據 (名稱+編號+taskid) 來判斷導入的檢測數據是否已經存在
          — 如果已經存在,根據導入的數據進行覆蓋
          — 如果不存在需要創建
          local attrs
          local strCondition = “S_ITEM_NAME='” .. strItemName .. “‘ and G_TASK_ID='”..strTaskID..”‘ and S_ITEM_CODE='” .. strItemCode.. “‘”
          nRet, strRetInfo = mobox.existThisData(strLuaDEID, “樣品技術參數”, strCondition)
          if (nRet ~= 0 ) then

          mobox.error(strLuaDEID, “在檢查樣品技術參數是否存在時失敗! ” .. strRetInfo)

          return
          end

          if (strRetInfo == ‘yes’) then

          — 已經存在,根據導入的數據進行覆蓋

          strCondition = “S_ITEM_NAME='” .. strItemName .. “‘ and G_TASK_ID='”..strTaskID..”‘ and S_ITEM_CODE='” .. strItemCode.. “‘”

          strSetSQL = “N_SN='” ..nSN.. “‘, S_ITEM_NAME = ‘” .. strItemName ..”‘ , S_ITEM_CODE ='” ..strItemCode .. “‘ , S_ITEM_M_S_N = ‘” .. strItemMSN ..”‘ “

          nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, “樣品技術參數”, strCondition, strSetSQL)

          if (nRet ~= 0) then

          mobox.error(strLuaDEID, strRetInfo)

          return

          end

          elseif (strRetInfo == ‘no’) then

          — 創建 樣品技術參數

          — mobox.writeSysLog(“strAddAttr1”, strAddAttr1)

          strAddAttr1 = ‘[‘ .. strAddAttr1 .. ‘]’

          mobox.writeSysLog(“strAddAttr2”, strAddAttr1)

          nRet, strRetInfo = mobox.createDataObj(strLuaDEID, “樣品技術參數”, strAddAttr1)

          if (nRet ~= 0) then

          mobox.error(strLuaDEID, “創建樣品技術參數失敗! ” .. strRetInfo )

          return
          end

          end
          end

           

          function
          標簽:手冊腳本 上一篇: 下一篇:
          展開更多
          預約軟件體驗

          loading...

          日本高清一二三区