Gungho任務(wù)二次開(kāi)發(fā)-任務(wù)分類集成3000功能的清單導(dǎo)入
這個(gè)是一個(gè)標(biāo)準(zhǔn)的導(dǎo)入模板 ,使用前可以通過(guò)修改 表名,字段名稱,字段中文名,字段對(duì)應(yīng)賦值變量名稱。
–[[
這個(gè)是一個(gè)標(biāo)準(zhǔn)的腳本,可以
1、修改里面的數(shù)據(jù)對(duì)象名稱 樣品技術(shù)參數(shù)
2、字段相關(guān)名稱(字段中文名、字段名稱、字段賦值變量名稱)
字段名稱? ? ? ? ? ? ? ? ? ? ? ? ? ? 字段中文名? ? ? ? ? 字段對(duì)應(yīng)賦值變量名
N_SN? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?序號(hào)? ? ? ? ? ? ? ? ? ? ?nSN
S_ITEM_NAME? ? ? ? ? ? ? ? ?名稱? ? ? ? ? ? ? ? ? ? ?strItemName
S_ITEM_M_S_N? ? ? ? ? ? ? ?型號(hào)_規(guī)格_數(shù)量? ?strItemMSN
S_ITEM_CODE? ? ? ? ? ? ? ? ?編號(hào)? ? ? ? ? ? ? ? ? ? ?strItemCode
S_MANUFACTURER? ? ? ? 生產(chǎn)單位? ? ? ? ? ? ? strFacturer
3、若字段不夠多,或太多,需要調(diào)整程序
4、里面的唯一性判斷是 task_id + S_ITEM_NAME + S_ITEM_CODE (需要根據(jù)情況調(diào)整)
–]]
功能說(shuō)明: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, “系統(tǒng)無(wú)法獲取全局變量 “..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, “必須要有項(xiàng)目及任務(wù)相關(guān)信息” )
return
end
— 獲取導(dǎo)入的單條數(shù)據(jù), 返回 {“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, “無(wú)法獲取導(dǎo)入數(shù)據(jù)!”..strRetInfo)
return
end
local n, nCount, nValue
local strAddAttr = ”
local strAttr = ”
local strSetSQL = ”
— 一些關(guān)鍵屬性 (腳本 后期只需要改字段名稱就可以)
local nSN? ? ? ? ? ? ? ? ? ? ? ? ? ?— 對(duì)應(yīng) 序號(hào) N_SN
local strItemName = ”? ? ? ? — 對(duì)應(yīng) 名稱 S_ITEM_NAME
local strItemMSN = ”? ? ? ? ?— 對(duì)應(yīng) 型號(hào)_規(guī)格_數(shù)量 S_ITEM_M_S_N
local strItemCode = ”? ? ? ? ?— 對(duì)應(yīng) 編號(hào) S_ITEM_CODE
local strFacturer = ”? ? ? ? ? ? — 對(duì)應(yīng) 生產(chǎn)單位 S_MANUFACTURER
— 因?yàn)槊看螌?dǎo)入只傳一條記錄,所以當(dāng)前條寫入 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導(dǎo)入的一行數(shù)據(jù),根據(jù)excel的列定義進(jìn)行屬性組合 strAddAttr
nCount = #input_rows
for n = 1, nCount do
strAttr = input_rows[n].attr
strValue = input_rows[n].value
— 根據(jù)導(dǎo)入的excel列頭名稱進(jìn)行判斷
— 關(guān)鍵屬性判斷
if (strAttr == “名稱”) then
if (strValue == ”) then
mobox.error(strLuaDEID, strAttr .. “不能為空!”)
return
end
strItemName = strValue
strAddAttr = strAddAttr .. ‘{“attr”:”S_ITEM_NAME”,”value”:”‘ .. strItemName .. ‘”},’
— 常規(guī)屬性
elseif (strAttr == “序號(hào)”) then
nSN = strValue
strAddAttr = strAddAttr .. ‘{“attr”:”N_SN”,”value”:”‘ .. nSN .. ‘”},’elseif (strAttr == “型號(hào)_規(guī)格_數(shù)量”) then
strItemMSN = strValue
strAddAttr = strAddAttr .. ‘{“attr”:”S_ITEM_M_S_N”,”value”:”‘ .. strItemMSN .. ‘”},’elseif (strAttr == “編 號(hào)”) then
strItemCode= strValue
strAddAttr = strAddAttr .. ‘{“attr”:”S_ITEM_CODE”,”value”:”‘ .. strItemCode .. ‘”},’elseif (strAttr == “生產(chǎn)廠家”) then
strFacturer = strValue
strAddAttr = strAddAttr .. ‘{“attr”:”S_MANUFACTURER”,”value”:”‘ .. strFacturer .. ‘”},’end
end
–去除最后一個(gè),
local strAddAttr1 = trim_laster_char(strAddAttr)— 步驟2 根據(jù) (名稱+編號(hào)+taskid) 來(lái)判斷導(dǎo)入的檢測(cè)數(shù)據(jù)是否已經(jīng)存在
— 如果已經(jīng)存在,根據(jù)導(dǎo)入的數(shù)據(jù)進(jìn)行覆蓋
— 如果不存在需要?jiǎng)?chuàng)建
local attrs
local strCondition = “S_ITEM_NAME='” .. strItemName .. “‘ and G_TASK_ID='”..strTaskID..”‘ and S_ITEM_CODE='” .. strItemCode.. “‘”
nRet, strRetInfo = mobox.existThisData(strLuaDEID, “樣品技術(shù)參數(shù)”, strCondition)
if (nRet ~= 0 ) thenmobox.error(strLuaDEID, “在檢查樣品技術(shù)參數(shù)是否存在時(shí)失敗! ” .. strRetInfo)
return
endif (strRetInfo == ‘yes’) then
— 已經(jīng)存在,根據(jù)導(dǎo)入的數(shù)據(jù)進(jìn)行覆蓋
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, “樣品技術(shù)參數(shù)”, strCondition, strSetSQL)
if (nRet ~= 0) then
mobox.error(strLuaDEID, strRetInfo)
return
end
elseif (strRetInfo == ‘no’) then
— 創(chuàng)建 樣品技術(shù)參數(shù)
— mobox.writeSysLog(“strAddAttr1”, strAddAttr1)
strAddAttr1 = ‘[‘ .. strAddAttr1 .. ‘]’
mobox.writeSysLog(“strAddAttr2”, strAddAttr1)
nRet, strRetInfo = mobox.createDataObj(strLuaDEID, “樣品技術(shù)參數(shù)”, strAddAttr1)
if (nRet ~= 0) then
mobox.error(strLuaDEID, “創(chuàng)建樣品技術(shù)參數(shù)失敗! ” .. strRetInfo )
return
endend
end
function