|
@@ -192,7 +192,6 @@ function getAllFiles( dir, file )
|
|
|
local fType, fName, fSize = io.readdir()
|
|
|
-- log.info("file or dir",fType, fName, fSize)
|
|
|
if fType == 32 then
|
|
|
- -- log.info("common file", fName, fSize)
|
|
|
local tname = split(fName,'-')
|
|
|
-- log.debug('func:getAllFiles tname',tname,tname[1],tname[2])
|
|
|
if tname[1] == file then
|
|
@@ -271,6 +270,7 @@ end
|
|
|
return false,count,'filename not fount'
|
|
|
end
|
|
|
if not dirPath then
|
|
|
+
|
|
|
log.error('func:getBaseInfo','dirPath not fount')
|
|
|
return false,count,'dirPath not fount'
|
|
|
end
|
|
@@ -280,55 +280,63 @@ end
|
|
|
if not files then
|
|
|
return false,count,desc
|
|
|
end
|
|
|
+ local succ_cnt = 0; --比较成功个数
|
|
|
for i,file in pairs(files) do
|
|
|
+ local isbreak = false
|
|
|
local path = dirPath..'/'..file
|
|
|
local filehandle = io.open(path, "r") -- 第一个参数是文件名,第二个是打开方式,'r'读模式,'w'写模式,对数据进行覆盖,'a'附加模式,'b'加在模式后面表示以二进制形式打开
|
|
|
if not filehandle then -- 判断文件是否存在
|
|
|
- break --不存在 跳过 查询下个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
fileval = filehandle:read("*all") -- 读出文件内容
|
|
|
-- print(fileval)
|
|
|
if not fileval then
|
|
|
- break --空文件 跳过读取下一个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
local filevaltable = split(fileval,delimiter)
|
|
|
local table_length = table_leng(filevaltable)
|
|
|
if table_length <= 1 then
|
|
|
- break --无'-'标识符 跳过读取下一个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
- local isBreak = false
|
|
|
-
|
|
|
- for a = 1,table_length-1 do
|
|
|
- local val = json.decode(filevaltable[a])
|
|
|
-
|
|
|
- if param then --有查询参数
|
|
|
- local p_length = table_leng(param) --条件长度
|
|
|
- local succ_cnt = 0; --比较成功个数
|
|
|
- for p,s in pairs(param) do
|
|
|
- if filename == "Users" then
|
|
|
- if p == 'pwd' then
|
|
|
- s = string.sub(string.upper(crypto.md5(s,#s,16)),9,24) --密码加密 加密结果32位 取16位(第9-24)字符
|
|
|
+
|
|
|
+ -- log.info("isbreak:", isbreak, table_length)
|
|
|
+
|
|
|
+ if not isbreak then
|
|
|
+ -- body
|
|
|
+ for a = 1,table_length-1 do
|
|
|
+ local val = json.decode(filevaltable[a])
|
|
|
+
|
|
|
+ if param then --有查询参数
|
|
|
+ local p_length = table_leng(param) --条件长度
|
|
|
+ for p,s in pairs(param) do
|
|
|
+ if filename == "Users" then
|
|
|
+ if p == 'pwd' then
|
|
|
+ s = string.sub(string.upper(crypto.md5(s,#s,16)),9,24) --密码加密 加密结果32位 取16位(第9-24)字符
|
|
|
+ end
|
|
|
+ end
|
|
|
+ -- log.info("val[p] ", val[p] , "s", s, succ_cnt)
|
|
|
+ if val[p] == s then
|
|
|
+ succ_cnt = succ_cnt + 1
|
|
|
+ else
|
|
|
+ break
|
|
|
end
|
|
|
end
|
|
|
- if val[p] == s then
|
|
|
- succ_cnt = succ_cnt + 1
|
|
|
- else
|
|
|
+ if p_length == succ_cnt then --找到结果 停止继续查找下个文件
|
|
|
+ selectRes[i] = val
|
|
|
+ isbreak = true
|
|
|
break
|
|
|
end
|
|
|
- end
|
|
|
- if p_length == succ_cnt then --找到结果 停止继续查找下个文件
|
|
|
+ else --无查询参数 查询所有
|
|
|
selectRes[i] = val
|
|
|
- isBreak = true
|
|
|
- break
|
|
|
end
|
|
|
- else --无查询参数 查询所有
|
|
|
- selectRes[i] = val
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
+
|
|
|
count = i
|
|
|
- if isBreak then --找到结果 停止继续查找下个文件
|
|
|
- break;
|
|
|
- end
|
|
|
+ -- if isbreak then --找到结果 停止继续查找下个文件
|
|
|
+ -- break;
|
|
|
+ -- end
|
|
|
filehandle:close() -- 关闭文件
|
|
|
end
|
|
|
-- print(table_leng(selectRes),json.encode(selectRes))
|
|
@@ -359,49 +367,57 @@ function getBaseInfo_ununique( filename,param,dirPath)
|
|
|
if not files then
|
|
|
return false,count,desc
|
|
|
end
|
|
|
+ local succ_cnt = 0; --比较成功个数
|
|
|
for i,file in pairs(files) do
|
|
|
+ local isbreak = false
|
|
|
local path = dirPath..'/'..file
|
|
|
local filehandle = io.open(path, "r") -- 第一个参数是文件名,第二个是打开方式,'r'读模式,'w'写模式,对数据进行覆盖,'a'附加模式,'b'加在模式后面表示以二进制形式打开
|
|
|
if not filehandle then -- 判断文件是否存在
|
|
|
- break --不存在 跳过 查询下个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
fileval = filehandle:read("*all") -- 读出文件内容
|
|
|
-- print(fileval)
|
|
|
if not fileval then
|
|
|
- break --空文件 跳过读取下一个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
local filevaltable = split(fileval,delimiter)
|
|
|
local table_length = table_leng(filevaltable)
|
|
|
if table_length <= 1 then
|
|
|
- break --无'-'标识符 跳过读取下一个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
- local isBreak = false
|
|
|
-
|
|
|
- for a = 1,table_length-1 do
|
|
|
- local val = json.decode(filevaltable[a])
|
|
|
+
|
|
|
|
|
|
- if param then --有查询参数
|
|
|
- local p_length = table_leng(param) --条件长度
|
|
|
- local succ_cnt = 0; --比较成功个数
|
|
|
- for p,s in pairs(param) do
|
|
|
+ if not isbreak then
|
|
|
+ -- body
|
|
|
+ for a = 1,table_length-1 do
|
|
|
+ local val = json.decode(filevaltable[a])
|
|
|
+ succ_cnt = 0
|
|
|
+ if param then --有查询参数
|
|
|
+ local p_length = table_leng(param) --条件长度
|
|
|
+ for p,s in pairs(param) do
|
|
|
|
|
|
- if val[p] == s then
|
|
|
- succ_cnt = succ_cnt + 1
|
|
|
- else
|
|
|
- break
|
|
|
+
|
|
|
+
|
|
|
+ if val[p] == s then
|
|
|
+ -- log.info("val[p]:", val[p], "s:",s)
|
|
|
+ succ_cnt = succ_cnt + 1
|
|
|
+ else
|
|
|
+ break
|
|
|
+ end
|
|
|
end
|
|
|
- end
|
|
|
-
|
|
|
- if p_length == succ_cnt then --找到结果 停止继续查找下个文件
|
|
|
+
|
|
|
+ if p_length == succ_cnt then --找到结果 停止继续查找下个文件
|
|
|
+ table.insert(selectRes, val)
|
|
|
+ end
|
|
|
+
|
|
|
+ else --无查询参数 查询所有
|
|
|
table.insert(selectRes, val)
|
|
|
end
|
|
|
-
|
|
|
- else --无查询参数 查询所有
|
|
|
- table.insert(selectRes, val)
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
count = i
|
|
|
- -- if isBreak then --找到结果 停止继续查找下个文件
|
|
|
+ -- if isbreak then --找到结果 停止继续查找下个文件
|
|
|
-- break;
|
|
|
-- end
|
|
|
filehandle:close() -- 关闭文件
|
|
@@ -434,67 +450,97 @@ function getBaseInfo_ununique_dim( filename,param,dirPath)
|
|
|
if not files then
|
|
|
return false,count,desc
|
|
|
end
|
|
|
+ local succ_cnt = 0; --比较成功个数
|
|
|
for i,file in pairs(files) do
|
|
|
+ local isbreak = false
|
|
|
local path = dirPath..'/'..file
|
|
|
local filehandle = io.open(path, "r") -- 第一个参数是文件名,第二个是打开方式,'r'读模式,'w'写模式,对数据进行覆盖,'a'附加模式,'b'加在模式后面表示以二进制形式打开
|
|
|
if not filehandle then -- 判断文件是否存在
|
|
|
- break --不存在 跳过 查询下个文件
|
|
|
+ isbreak = true
|
|
|
+ -- isbreak = true
|
|
|
end
|
|
|
fileval = filehandle:read("*all") -- 读出文件内容
|
|
|
-- print(fileval)
|
|
|
if not fileval then
|
|
|
- break --空文件 跳过读取下一个文件
|
|
|
+ isbreak = true
|
|
|
+ -- isbreak = true
|
|
|
end
|
|
|
local filevaltable = split(fileval,delimiter)
|
|
|
local table_length = table_leng(filevaltable)
|
|
|
if table_length <= 1 then
|
|
|
- break --无'-'标识符 跳过读取下一个文件
|
|
|
+ isbreak = true
|
|
|
+ -- isbreak = true
|
|
|
end
|
|
|
- local isBreak = false
|
|
|
-
|
|
|
- for a = 1,table_length-1 do
|
|
|
- local val = json.decode(filevaltable[a])
|
|
|
-
|
|
|
- if param then --有查询参数
|
|
|
- local p_length = table_leng(param) --条件长度
|
|
|
- local succ_cnt = 0; --比较成功个数
|
|
|
- local pattern = ""
|
|
|
- for p,s in pairs(param) do
|
|
|
-
|
|
|
- if succ_cnt > 19 then
|
|
|
- -- body
|
|
|
- break
|
|
|
- end
|
|
|
-
|
|
|
-
|
|
|
- local wholeStr = val[p]
|
|
|
- if type(val[p]) ~= "userdata" then
|
|
|
- -- body
|
|
|
- pattern = string.gsub(s, "[%[%]&=+%%%c%(%)%-%/%+]", function(c)
|
|
|
- return "%"..c
|
|
|
- end)
|
|
|
- local a,b = string.find(wholeStr,pattern)
|
|
|
- local transMatchres = string.match(wholeStr,pattern)
|
|
|
+
|
|
|
+ if not isbreak then
|
|
|
+ -- body
|
|
|
+ for a = 1,table_length-1 do
|
|
|
+ local val = json.decode(filevaltable[a])
|
|
|
|
|
|
-
|
|
|
- if a and (b-a+1) == #transMatchres then
|
|
|
- succ_cnt = succ_cnt + 1
|
|
|
- table.insert(selectRes, val)
|
|
|
+ if param then --有查询参数
|
|
|
+ local p_length = table_leng(param) --条件长度
|
|
|
+ local pattern = ""
|
|
|
+ for p,s in pairs(param) do
|
|
|
+
|
|
|
+ if succ_cnt > 49 then
|
|
|
+ -- body
|
|
|
+ break
|
|
|
+ end
|
|
|
+
|
|
|
+ -- log.info("val[p]:", val[p], "s:",s)
|
|
|
+
|
|
|
+ local wholeStr = val[p]
|
|
|
+ if type(val[p]) ~= "userdata" then
|
|
|
+ -- body
|
|
|
+ pattern = string.gsub(s, "[%[%]&=+%%%c%(%)%-%/%+]", function(c)
|
|
|
+ return "%"..c
|
|
|
+ end)
|
|
|
+ local a,b = string.find(wholeStr,pattern)
|
|
|
+ local transMatchres = string.match(wholeStr,pattern)
|
|
|
+
|
|
|
+
|
|
|
+ if a and (b-a+1) == #transMatchres then
|
|
|
+ succ_cnt = succ_cnt + 1
|
|
|
+ table.insert(selectRes, val)
|
|
|
+ end
|
|
|
end
|
|
|
+
|
|
|
end
|
|
|
+
|
|
|
+ -- if p_length == succ_cnt then --找到结果 停止继续查找下个文件
|
|
|
+ -- table.insert(selectRes, val)
|
|
|
+ -- end
|
|
|
+
|
|
|
+ else --无查询参数 查询所有
|
|
|
+ if succ_cnt > 49 then
|
|
|
+ -- body
|
|
|
+ else
|
|
|
|
|
|
+ if filename == "Wind" then
|
|
|
+ -- body
|
|
|
+ local fieldDisplayRadius = nvm.get("fieldDisplayRadius") or 200
|
|
|
+ local gpsLng, gpsLat = nvm.get("gpsLng"), nvm.get("gpsLat")
|
|
|
+ local dist = devTool.getDistance( val.lat, val.lon, gpsLat, gpsLng)
|
|
|
+ -- log.info("dist:",dist, json.encode(v))
|
|
|
+ if dist < fieldDisplayRadius then
|
|
|
+ -- body
|
|
|
+ -- log.info("cicle",v.lat)
|
|
|
+ val.dist = dist
|
|
|
+ table.insert(selectRes, val)
|
|
|
+ succ_cnt = succ_cnt+1
|
|
|
+ end
|
|
|
+ else
|
|
|
+ table.insert(selectRes, val)
|
|
|
+ succ_cnt = succ_cnt+1
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
end
|
|
|
-
|
|
|
- -- if p_length == succ_cnt then --找到结果 停止继续查找下个文件
|
|
|
- -- table.insert(selectRes, val)
|
|
|
- -- end
|
|
|
-
|
|
|
- else --无查询参数 查询所有
|
|
|
- table.insert(selectRes, val)
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
count = i
|
|
|
- -- if isBreak then --找到结果 停止继续查找下个文件
|
|
|
+ -- if isbreak then --找到结果 停止继续查找下个文件
|
|
|
-- break;
|
|
|
-- end
|
|
|
filehandle:close() -- 关闭文件
|
|
@@ -542,35 +588,40 @@ function delBaseInfo(filename,id,dirPath)
|
|
|
end
|
|
|
local isCurFile = false --要删除文件是否找到
|
|
|
for i,file in pairs(files) do
|
|
|
+ local isbreak = false
|
|
|
local path = dirPath..'/'..file
|
|
|
local filehandle = io.open(path, "r") -- 第一个参数是文件名,第二个是打开方式,'r'读模式,'w'写模式,对数据进行覆盖,'a'附加模式,'b'加在模式后面表示以二进制形式打开
|
|
|
if not filehandle then -- 判断文件是否存在
|
|
|
- break --不存在 跳过 查询下个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
fileval = filehandle:read("*all") -- 读出文件内容
|
|
|
if not fileval then
|
|
|
- break --空文件 跳过读取下一个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
local filevaltable = split(fileval,delimiter)
|
|
|
local table_lenght = table_leng(filevaltable)
|
|
|
if table_lenght <= 1 then
|
|
|
- break --无'-'标识符 跳过读取下一个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
local newfileval = "" --删除后文件内容
|
|
|
- for a = 1,table_lenght-1 do
|
|
|
- local val = json.decode(filevaltable[a])
|
|
|
-
|
|
|
- if val.id ~= id then
|
|
|
- data = json.encode(val)
|
|
|
- if newfileval ~= "" then
|
|
|
- newfileval = newfileval..data..delimiter
|
|
|
+ if not isbreak then
|
|
|
+ -- body
|
|
|
+ for a = 1,table_lenght-1 do
|
|
|
+ local val = json.decode(filevaltable[a])
|
|
|
+
|
|
|
+ if val.id ~= id then
|
|
|
+ data = json.encode(val)
|
|
|
+ if newfileval ~= "" then
|
|
|
+ newfileval = newfileval..data..delimiter
|
|
|
+ else
|
|
|
+ newfileval = data..delimiter
|
|
|
+ end
|
|
|
else
|
|
|
- newfileval = data..delimiter
|
|
|
+ isCurFile = true
|
|
|
end
|
|
|
- else
|
|
|
- isCurFile = true
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
filehandle:close() -- 关闭文件
|
|
|
if isCurFile then
|
|
|
--删除旧文件
|
|
@@ -625,41 +676,46 @@ function updateBaseInfo( filename,data,dirPath)
|
|
|
end
|
|
|
local isCurFile = false --要修改数据文件是否找到
|
|
|
for i,file in pairs(files) do
|
|
|
+ local isbreak = false
|
|
|
local path = dirPath..'/'..file
|
|
|
local filehandle = io.open(path, "r") -- 第一个参数是文件名,第二个是打开方式,'r'读模式,'w'写模式,对数据进行覆盖,'a'附加模式,'b'加在模式后面表示以二进制形式打开
|
|
|
if not filehandle then -- 判断文件是否存在
|
|
|
- break --不存在 跳过 查询下个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
fileval = filehandle:read("*all") -- 读出文件内容
|
|
|
if not fileval then
|
|
|
- break --空文件 跳过读取下一个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
local filevaltable = split(fileval,delimiter)
|
|
|
local table_length = table_leng(filevaltable)
|
|
|
if table_length <= 1 then
|
|
|
- break --无'-'标识符 跳过读取下一个文件
|
|
|
+ isbreak = true
|
|
|
end
|
|
|
local newfileval = nil --删除后文件内容
|
|
|
- for a = 1,table_length-1 do
|
|
|
- local val = json.decode(filevaltable[a])
|
|
|
- if val.id ~= data.id then --过滤要修改的那条数据
|
|
|
- dataStr = json.encode(val)
|
|
|
- if newfileval then
|
|
|
- newfileval = newfileval..dataStr..delimiter
|
|
|
- else
|
|
|
- newfileval = dataStr..delimiter
|
|
|
- end
|
|
|
- else
|
|
|
- --将新数据放入新的文件内容中
|
|
|
- local newData = json.encode(data)
|
|
|
- if newfileval then
|
|
|
- newfileval = newfileval..newData..delimiter
|
|
|
+ if not isbreak then
|
|
|
+ -- body
|
|
|
+ for a = 1,table_length-1 do
|
|
|
+ local val = json.decode(filevaltable[a])
|
|
|
+ if val.id ~= data.id then --过滤要修改的那条数据
|
|
|
+ dataStr = json.encode(val)
|
|
|
+ if newfileval then
|
|
|
+ newfileval = newfileval..dataStr..delimiter
|
|
|
+ else
|
|
|
+ newfileval = dataStr..delimiter
|
|
|
+ end
|
|
|
else
|
|
|
- newfileval = newData..delimiter
|
|
|
+ --将新数据放入新的文件内容中
|
|
|
+ local newData = json.encode(data)
|
|
|
+ if newfileval then
|
|
|
+ newfileval = newfileval..newData..delimiter
|
|
|
+ else
|
|
|
+ newfileval = newData..delimiter
|
|
|
+ end
|
|
|
+ isCurFile = true
|
|
|
end
|
|
|
- isCurFile = true
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
filehandle:close() -- 关闭文件
|
|
|
if isCurFile then
|
|
|
if newfileval then
|