function DayFromat(dateTimeStr) local formattedDateStr ="" if (dateTimeStr == "" or dateTimeStr==nil ) then return formattedDateStr end dateTimeStr = string.gsub(dateTimeStr, "T", " ") print(dateTimeStr) -- 使用模式匹配提取日期和時(shí)間部分 local dateStr, timeStr = dateTimeStr:match("(%d+-%d+-%d+) (%d+:%d+:%d+)") if (dateStr == nil) then formattedDateStr ="Date Format Error" return formattedDateStr end -- 提取日期部分的年、月、日 local year, month, day = dateStr:match("(%d+)-(%d+)-(%d+)") -- 將提取的月、日格式化為兩位數(shù)的字符串 month = string.format("%02d", tonumber(month)) day = string.format("%02d", tonumber(day)) -- 組合格式化后的日期和原始時(shí)間部分 local formattedDateStr = string.format("%s-%s-%s", year, month, day) local formattedDateTime = string.format("%s %s", formattedDateStr, timeStr) return formattedDateStr end
— 示例使用
local date = “2024-03-25T16:00:00.000Z”
local formattedDate = DayFromat(date)
print(formattedDate) — 輸出: 2024-03-25
nRet, strOBJInfo = mobox.objAttrToObjJson (‘PMS001’, strRetInfo )
沒(méi)有對(duì)執(zhí)行做保護(hù)(原先理解是 絕對(duì)不會(huì)出錯(cuò)的,實(shí)際上是錯(cuò)了),執(zhí)行后報(bào)錯(cuò)
這個(gè)錯(cuò)誤爆出,我們根本無(wú)法判斷問(wèn)題所在。所以在任何情況下調(diào)用函數(shù)都需要做 出錯(cuò)保護(hù),加入
?if (nRet ~= 0) then
mobox.error(strLuaDEID, “PMS001數(shù)據(jù)庫(kù)沒(méi)有對(duì)應(yīng)字段 “)
return
end
2、在Debug 函數(shù)里面不能包含表類型的變量
Debug( strLuaDEID, debug.getinfo(1), ‘keynode創(chuàng)建’,tbNote[1])
里面的 tbNote[1]是一個(gè)表類型的變量,debug 不支持這個(gè)格式
nRet, strOBJInfo = mobox.objAttrToObjJson (‘JS003’, strRetInfo )
]]>
— 功能:
— 3000 功能點(diǎn) 列出與某一個(gè)taskid相關(guān)的數(shù)據(jù)
— 若列出數(shù)據(jù)已經(jīng)有,將 新增 頁(yè)面按鈕屏蔽 (這個(gè)功能是做任務(wù)評(píng)測(cè)結(jié)果的,結(jié)果只能有一個(gè),不可能多個(gè))
————————————————————————–
json = require (“json”)
mobox = require (“OILua_JavelinExt”)function shownowtaskdata ( strLuaDEID )local nRet, strRetInfo local nType local strTaskID local bHidden=false local strClsID=""--拿到數(shù)據(jù)對(duì)象標(biāo)識(shí) nRet, strRetInfo = mobox.getCurEditExtInfo( strLuaDEID ) if ( nRet ~= 0 ) then mobox.error( strLuaDEID, "系統(tǒng)獲取擴(kuò)展屬性失敗 "..strRetInfo ) return end if ( strRetInfo =='' or strRetInfo==nil or strRetInfo=='{}' ) then mobox.error( strLuaDEID, "系統(tǒng)獲取擴(kuò)展屬性為空!" ) return end local extinfo = json.decode( strRetInfo ) strClsID=extinfo.cls_id -- 得到當(dāng)前cls的id ,下面操作需要— 獲取任務(wù)全局屬性 (這個(gè)案例是與 Gungho任務(wù)系統(tǒng)集成,所以需要這個(gè)參數(shù),別的環(huán)境這個(gè)可以忽略
nRet, strRetInfo = mobox.getGlobalAttr( strLuaDEID, “task_id” )
if ( nRet ~= 0 or strRetInfo == ” ) then
mobox.error( strLuaDEID, “系統(tǒng)無(wú)法獲取任務(wù)號(hào) “..strRetInfo )
return
end
local input_paramter = json.decode( strRetInfo )
local strTaskID = input_paramter[1].valuelocal strCondition strCondition = "G_TASK_ID='"..strTaskID.."'" --增加隱藏按鈕的依據(jù)-通過(guò)條件查詢返回符合數(shù)據(jù)>0 既隱藏 -- local strQeuryCondition="S_TESTITEM='X'" (定義grid某一個(gè)字段內(nèi)有某些數(shù)值 這里沒(méi)有啟用) nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, strClsID, strCondition) if (nRet ~= 0 ) then mobox.error(strLuaDEID, "得到數(shù)據(jù)數(shù)量失敗,原因:" .. strRetInfo) return end --轉(zhuǎn)為整數(shù)類型 local nDataCount = tonumber(strRetInfo) if (nDataCount >0) then bHidden=true end --隱藏頁(yè)面按鈕 “新增” local strHiddenButton = '' if (bHidden) then strHiddenButton = ',{"action_type":"hidden_button","value":[{"name":"新增"}]}' end local strAction = '[{"action_type":"set_query_condition","value":{"where":"' .. strCondition .. '","order":""}}' strAction = strAction .. strHiddenButton .. ']' mobox.setAction( strLuaDEID, strAction )end
這個(gè)列子也可以用于別的一些非法字符串的處理
]]>為了解決這個(gè)問(wèn)題,我們可以編輯一個(gè)lua腳本,將這個(gè)數(shù)據(jù)做處理后再顯示(在顯示前事件里面定義這個(gè)lua腳本)
–[[? ? 功能說(shuō)明:? ? ? ? 1) 顯示前做一些字段的處理? ? ? ? 2)前端導(dǎo)入,新增有換行符號(hào) %%3Cbr%%3E ,替換成 <br> 前端html支持的換行內(nèi)容? ? ? ? 3)內(nèi)容中有&,替換成 & 前端解析 &不支持,最好在輸入時(shí)進(jìn)行替換–]]json = require(“json”)mobox = require(“OILua_JavelinExt”)require(“oi_basestrfunc”)function BeforeGridShow(strLuaDEID)? ? local nRet, strRetInfo? ? local arobjs, attrs, success? ? — 獲取輸入的DataJson數(shù)據(jù)包? ? nRet, strRetInfo = mobox.getCurEditDataPacket(strLuaDEID)? ? if (nRet ~= 0) then? ? ? ? mobox.error(strLuaDEID, “無(wú)法獲取數(shù)據(jù)包!”)? ? ? ? return? ? end? ? if (strRetInfo == ” or strRetInfo == nil) then? ? ? ? return? ? end? ? — 解析數(shù)據(jù)包,數(shù)據(jù)包格式? ? — [{“id”:””,”attrs”:[{“attr”:””,”value”:””},..]},..]? ? local n, nCount? ? success, arobjs = pcall(json.decode, strRetInfo)? ? if (success == false) then? ? ? ? mobox.error(strLuaDEID, “非法的JSON格式!”)? ? ? ? return? ? end? ? nCount = #arobjs? ? if (nCount == 0) then? ? ? ? return? ? end? ? local obj, attrs? ? local nattr_count? ? local strRow, strAttr, strItem? ? local strDataJson? ? local id, strValue? ? local strAttrs? ? strDataJson = ‘[‘? ? local seg = {}? ? local nSegCount = 0? ? for n = 1, nCount do? ? ? ? obj = arobjs[n]? ? ? ? attrs = obj.attrs? ? ? ? nattr_count = #attrs? ? ? ? id = obj.id? ? ? ? strAttrs=”? ? ? ? — 開(kāi)始過(guò)濾顯示數(shù)據(jù)對(duì)象屬性? ? ? ? for nIndex = 1, nattr_count do? ? ? ? ? ? strAttr = attrs[nIndex].attr? ? ? ? ? ? strValue = attrs[nIndex].value? ? ? ? ? ? strValue = strValue:gsub(“%%3Cbr%%3E”, “<br>”)? ? ? ? ? ? strValue = strValue:gsub(“&”, “&”)? ? ? ? ? ? strItem = ‘{“attr”:”‘ .. strAttr .. ‘”,”value”:”‘ .. strValue .. ‘”},’? ? ? ? ? ? strAttrs = strAttrs .. strItem? ? ? ? end? ? ? ? — 取消最后一個(gè),號(hào)? ? ? ? strAttrs = trim_laster_char(strAttrs)? ? ? ? strRow = ‘{“id”:”‘ .. id .. ‘”,”attrs”:[‘ .. strAttrs .. ‘]},’? ? ? ? strDataJson = strDataJson .. strRow? ? end? ? — 取消最后一個(gè),號(hào)? ? strDataJson = trim_laster_char(strDataJson)? ? strDataJson = strDataJson .. ‘]’? ? local strAction = ‘[{“action_type”:”reset_data_attr”,”value”:’ .. strDataJson .. ‘}]’? ? mobox.setAction(strLuaDEID, strAction)end
這個(gè)列子也可以用于別的一些非法字符串的處理
]]>
企業(yè)在實(shí)施項(xiàng)目管理系統(tǒng)的時(shí)候,不通類型的項(xiàng)目其屬性可能是不一樣的。而Gungho標(biāo)準(zhǔn)系統(tǒng)內(nèi)對(duì)項(xiàng)目的屬性,主要包括(項(xiàng)目名稱、編號(hào)、開(kāi)始結(jié)束日期等)。為了適應(yīng)企業(yè)個(gè)性項(xiàng)目信息的輸入,我們需要通過(guò)Mobox平臺(tái)定義項(xiàng)目類型去適應(yīng)這個(gè)需求
Sa 登錄mobox低代碼開(kāi)發(fā)平臺(tái)
創(chuàng)建一個(gè)用于描述項(xiàng)目擴(kuò)展屬性的數(shù)據(jù)對(duì)象
注意:業(yè)務(wù)類型必須是 項(xiàng)目
接下來(lái)需要做的內(nèi)容,這里不具體展開(kāi)
基礎(chǔ):主要是綁定哪個(gè)數(shù)據(jù)對(duì)象及相關(guān)的界面
功能:主要是可以自定義該類型項(xiàng)目的自定義菜單 (參考下圖)
我們?cè)趃ungho登錄后,新建項(xiàng)目
這個(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)前條寫(xiě)入 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
]]>
我們?cè)趯?shí)施Gungho項(xiàng)目管理系統(tǒng)剛上線的時(shí)候,其實(shí)用戶手上有很多的歷史項(xiàng)目需要導(dǎo)入進(jìn)來(lái)。而且用戶的項(xiàng)目屬性與我們標(biāo)準(zhǔn)的項(xiàng)目屬性差異很大。為此,我們需要對(duì)Gungho的項(xiàng)目數(shù)據(jù)屬性進(jìn)行擴(kuò)延。而這個(gè)擴(kuò)延設(shè)置是在Mobox數(shù)據(jù)平臺(tái)來(lái)完成的。為此我們需要做2個(gè)事情:
給項(xiàng)目設(shè)置擴(kuò)展屬性,用于對(duì)用戶需求的適應(yīng)
需要將企業(yè)歷史項(xiàng)目清單一次性導(dǎo)入
因?yàn)椋覀兪菫镚ungho的項(xiàng)目管理做配套,所以在mobox建立數(shù)據(jù)模型的時(shí)候,有類型需要選擇? ,業(yè)務(wù)類型必須是 “項(xiàng)目”
目的,定義適用企業(yè)個(gè)性需求的項(xiàng)目管理功能及界面
根據(jù)需求 自定義功能
根據(jù)需求,加入對(duì)應(yīng)腳本
方法一: ?(這個(gè)一般在mobox數(shù)據(jù)對(duì)象創(chuàng)建后事件調(diào)用)
Mobox 數(shù)據(jù)對(duì)象先創(chuàng)建 –》之后通過(guò)腳本生成Gungho的項(xiàng)目 –》得到Gungho項(xiàng)目的prj_id –》更新mobox數(shù)據(jù)對(duì)象的 G_PRJ_ID
local strPrjInfo
strPrjInfo = ‘{“type“:”漢和項(xiàng)目”,”name“:”‘ .. strPrjName .. ‘”,’
strPrjInfo = strPrjInfo .. ‘”pm_login“:”‘ .. strPMID .. ‘”,”pm_name“:”‘ .. strPMName .. ‘”,’
strPrjInfo = strPrjInfo .. ‘”pd_login“:”‘ .. strPDID .. ‘”,”pd_name“:”‘ .. strPDName .. ‘”,’
— type:定義了項(xiàng)目類型? ? ? ?name:項(xiàng)目名稱
strPrjInfo = strPrjInfo .. ‘”class_name“:”項(xiàng)目”,”obj_id“:”‘ .. strObjID .. ‘”,’
— class_name:數(shù)據(jù)對(duì)象名稱? obj_id:數(shù)據(jù)對(duì)象ID ,Mobox數(shù)據(jù)創(chuàng)建后獲取
strPrjInfo = strPrjInfo .. ‘”code“:”‘ .. strPrjCode .. ‘”,’
strPrjInfo = strPrjInfo .. ‘”role“:[{“name”:”項(xiàng)目總監(jiān)”,”user”:[{“login”:”‘ .. strPDID .. ‘”,”name”:”‘ ..?strPDName .. ‘”}]}’ .. strPrjRoleMember .. ‘]}’
— code:項(xiàng)目編號(hào)? role:角色相關(guān)
— 向共好系統(tǒng)創(chuàng)建一個(gè)項(xiàng)目
nRet, strRetInfo = mobox.createProject(strLuaDEID, strPrjInfo)
— strRetInfo:返回的是gungho創(chuàng)建項(xiàng)目的ID (prj_id)
if (nRet ~= 0) then
mobox.error(strLuaDEID, strRetInfo)
return
end
— strRetInfo:這個(gè)要回寫(xiě)Mobox數(shù)據(jù)對(duì)象的 G_PRJ_ID
— 得到prj_id 將信息寫(xiě)入mobox數(shù)據(jù)對(duì)象的代碼,這里就不展現(xiàn)了
方法二: ?(這個(gè)一般在mobox數(shù)據(jù)對(duì)象的自定義事件入“項(xiàng)目導(dǎo)入”調(diào)用)
Gungho的項(xiàng)目所需的所有信息(包括擴(kuò)展信息)全部定義好,一次性創(chuàng)建Gungho及Mobox所有數(shù)據(jù)及其相關(guān)性
?strPrjInfo = ‘{“type”:”漢和項(xiàng)目”,”class_name”:”項(xiàng)目”,”name”:”‘ .. strPrjName .. ‘”,’
strPrjInfo = strPrjInfo .. ‘”pm_login”:”‘ .. strPMID .. ‘”,”pm_name”:”‘ .. strPMName .. ‘”,’
strPrjInfo = strPrjInfo .. ‘”pd_login”:”‘ .. strPDID .. ‘”,”pd_name”:”‘ .. strPDName .. ‘”,’
strPrjInfo = strPrjInfo .. ‘”code”:”‘ .. strPrjCode .. ‘”,’
— 拼接項(xiàng)目的角色屬性
strPrjInfo = strPrjInfo .. ‘”role”:[{“name”:”項(xiàng)目總監(jiān)”,”user”:[{“login”:”‘ .. strPDID .. ‘”,”name”:”‘ ..? strPDName .. ‘”}]}’ .. strPrjRoleMember .. ‘],’
— 拼接項(xiàng)目的擴(kuò)展項(xiàng)目屬性
strPrjInfo = strPrjInfo .. ‘”ext_obj_attr“:[‘ .. strAddAttr1 .. ‘]}’
— ext_obj_attr 項(xiàng)目創(chuàng)建的時(shí)候,帶擴(kuò)展屬性(strAddAttr1 變量事先拼接好了)
— 帶擴(kuò)展屬性,會(huì)同時(shí)將mobox數(shù)據(jù)對(duì)象及gungho的項(xiàng)目都創(chuàng)建起來(lái),并關(guān)聯(lián)好
nRet, strRetInfo = mobox.createProject(strLuaDEID, strPrjInfo)
–strRetInfo 返回參數(shù) 為兩個(gè)GUID :項(xiàng)目ID ;
— 返回的內(nèi)容如:
— ‘{A52E97CF-BDBE-4EA7-AAD6-949AD5707BF3};{1CB2B481-CA23-42DB-B7A2-546C1EA05364}’
我們系統(tǒng)上線的時(shí)候,原先的歷史數(shù)據(jù)是沒(méi)有的,為了快速接軌企業(yè)已有數(shù)據(jù),我們可以通過(guò)excel 對(duì)歷史數(shù)據(jù)進(jìn)行導(dǎo)入操作。導(dǎo)入一般可以通過(guò)腳本做一些定制開(kāi)發(fā)來(lái)實(shí)現(xiàn)
列子:
數(shù)據(jù)導(dǎo)入的sheet 要求
這個(gè)系統(tǒng)只能導(dǎo)入,左邊第一個(gè)sheet (命名無(wú)所謂)(注意:若數(shù)據(jù)列表 這個(gè)sheet左邊還有隱藏的sheet,那么系統(tǒng)也不能獲取 數(shù)據(jù)列表sheet頁(yè)的數(shù)據(jù))
對(duì)Excel單元格的要求
單元個(gè)里面的數(shù)據(jù),只能是字符串或數(shù)值。若是計(jì)算公式或函數(shù) ,將無(wú)法獲取
另外,單元個(gè)內(nèi)容 不能出現(xiàn) /\<> & 符號(hào),不能有換行或大量空格
1、字段分3類:
如,產(chǎn)品名稱 ,這個(gè)是必須有數(shù)值的
用于登記各種屬性信息
若有數(shù)據(jù),則直接獲取
若沒(méi)有,可以通過(guò)lua腳本計(jì)算生成
這種字段,一般也是必須有數(shù)值的
2、第一行是表頭行,數(shù)據(jù)行從第二行開(kāi)始
通過(guò)Mobox 3000 功能點(diǎn)進(jìn)行定義,設(shè)置界面如下:
導(dǎo)入腳本,參考:
json? = require(“json”)mobox = require(“OILua_JavelinExt”)require(“oi_basestrfunc”)function ImportKA(strLuaDEID)? ? local nRet, strRetInfo? ? — 獲取導(dǎo)入的數(shù)據(jù), 返回 [[{“attr”:”xx”,”value”:””},…]]? ? — V2.0? ? nRet, strRetInfo = mobox.getCurEditDataPacket(strLuaDEID)? ? if (nRet ~= 0 or strRetInfo == ”) then? ? ? ? mobox.error(strLuaDEID, “無(wú)法獲取導(dǎo)入數(shù)據(jù)!”)? ? ? ? return? ? end? ? local input_rows = json.decode(strRetInfo)? ? local n, nCount, nValue, nMaxRow, nRow? ? local strAddAttr = ”? ? — 一些關(guān)鍵屬性? ? local strKAName = ”? ? local strKAType = ”? ? local strArea = ”? ? — 步驟1 獲取從excel導(dǎo)入的一行數(shù)據(jù),根據(jù)excel的列定義進(jìn)行屬性組合 strAddAttr? ? nMaxRow = #input_rows? ? for nRow = 1, nMaxRow do? ? ? ? input = input_rows[nRow]? ? ? ? nCount = #input? ? ? ? — V2.1? ? ? ? strAddAttr = ”? ? ? ? strKAName = ”? ? ? ? strKAType = ”? ? ? ? strArea = ”? ? ? ? for n = 1, nCount do? ? ? ? ? ? strAttr = input[n].attr? ? ? ? ? ? strValue = input[n].value? ? ? ? ? ? if (strAttr ~= ” and strValue ~= ”) then? ? ? ? ? ? ? ? — 根據(jù)導(dǎo)入的excel列頭名稱進(jìn)行判斷? ? ? ? ? ? ? ? — 關(guān)鍵屬性判斷? ? ? ? ? ? ? ? if (strAttr == “客戶名稱”) then? ? ? ? ? ? ? ? ? ? if (strValue == ”) then? ? ? ? ? ? ? ? ? ? ? ? mobox.error(strLuaDEID, strAttr .. “不能為空!”)? ? ? ? ? ? ? ? ? ? ? ? return? ? ? ? ? ? ? ? ? ? end? ? ? ? ? ? ? ? ? ? strKAName = strValue? ? ? ? ? ? ? ? ? ? strAddAttr = strAddAttr .. ‘{“attr”:”S_KA_NAME”,”value”:”‘ .. strKAName .. ‘”},’? ? ? ? ? ? ? ?— 常規(guī)屬性? ? ? ? ? ? ? ? elseif (strAttr == “所屬地區(qū)”) then? ? ? ? ? ? ? ? ? ? strArea = strValue? ? ? ? ? ? ? ? ? ? strAddAttr = strAddAttr .. ‘{“attr”:”S_AREA”,”value”:”‘ .. strArea .. ‘”},’? ? ? ? ? ? ? ? elseif (strAttr == “客戶類型”) then? ? ? ? ? ? ? ? ? ? strKAType = strValue? ? ? ? ? ? ? ? ? ? strAddAttr = strAddAttr .. ‘{“attr”:”S_KA_TYPE”,”value”:”‘ .. strKAType .. ‘”},’? ? ? ? ? ? ? ? end? ? ? ? ? ? end? ? ? ? end? ? ? ? –去除最后一個(gè),? ? ? ? local strAddAttr1 = trim_laster_char(strAddAttr)? ? ? ? — 步驟2 根據(jù)客戶名稱來(lái)判斷導(dǎo)入的客戶是否已經(jīng)存在? ? ? ? —? ? ? ?如果已經(jīng)存在,根據(jù)導(dǎo)入的數(shù)據(jù)進(jìn)行覆蓋? ? ? ? —? ? ? ?如果不存在需要?jiǎng)?chuàng)建? ? ? ? local attrs? ? ? ? local strCondition = “S_KA_NAME='” .. strKAName .. “‘”? ? ? ? nRet, strRetInfo = mobox.existThisData(strLuaDEID, “客戶”, strCondition)? ? ? ? if (nRet ~= 0) then? ? ? ? ? ? mobox.error(strLuaDEID, “在檢查客戶是否存在時(shí)失敗! ” .. strRetInfo)? ? ? ? ? ? return? ? ? ? end? ? ? ? if (strRetInfo == ‘yes’) then? ? ? ? ? ? — 已經(jīng)存在,根據(jù)導(dǎo)入的數(shù)據(jù)進(jìn)行覆蓋? ? ? ? ? ? strCondition = “S_KA_NAME='” .. strKAName .. “‘”? ? ? ? ? ? strSetSQL =? “S_KA_NAME = ‘” .. strKAName ..”‘ , S_KA_TYPE ='” ..strKAType .. “‘ , S_AREA = ‘” .. strArea ..”‘ “? ? ? ? ? ? nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, “客戶”, strCondition, strSetSQL)? ? ? ? ? ? if (nRet ~= 0) then? ? ? ? ? ? ? ? mobox.error(strLuaDEID, strRetInfo)? ? ? ? ? ? ? ? return? ? ? ? ? ? end? ? ? ? elseif (strRetInfo == ‘no’) then? ? ? ? ? ? — 創(chuàng)建客戶? ? ? ? ? ? –mobox.writeSysLog(“strAddAttr1”, strAddAttr1)? ? ? ? ? ? strAddAttr1 = ‘[‘ .. strAddAttr1 .. ‘]’? ? ? ? ? ? –mobox.writeSysLog(“strAddAttr2”, strAddAttr1)? ? ? ? ? ? nRet, strRetInfo = mobox.createDataObj(strLuaDEID, “客戶”, strAddAttr1)? ? ? ? ? ? if (nRet ~= 0) then? ? ? ? ? ? ? ? mobox.error(strLuaDEID, “創(chuàng)建客戶失敗! ” .. strRetInfo )? ? ? ? ? ? ? ? return? ? ? ? ? ? end? ? ? ? end? ? endend
數(shù)據(jù)對(duì)象它有生命周期:編輯 -> 審核 -> 定版 -> 報(bào)廢? (默認(rèn) 4個(gè)狀態(tài))
我們數(shù)據(jù)在輸入階段,那么就屬于 “編輯”? ,這個(gè)時(shí)候可以修改與之相關(guān)的屬性及關(guān)聯(lián)關(guān)系。而一定數(shù)據(jù)對(duì)象經(jīng)過(guò)審核 ,進(jìn)入“定版” 狀態(tài),那么針對(duì)這個(gè)數(shù)據(jù)對(duì)象就不能修改了
參考下圖:
為實(shí)現(xiàn)這個(gè)功能設(shè)置,Mobox系統(tǒng)需要做如下配置
-》在grid列表定義里面 ,必須有 “S_STATE” 狀態(tài)? 這個(gè)字段
若這個(gè)字段不設(shè)置到 grid ,就無(wú)法實(shí)現(xiàn)第一圖的效果
]]>