缺陷查询添加integer_done类型处理(暂未用上)

This commit is contained in:
z9hang 2014-12-29 11:54:31 +08:00
parent 6192a36481
commit 3f6b36096c
1 changed files with 9 additions and 0 deletions

View File

@ -173,6 +173,7 @@ class Query < ActiveRecord::Base
:string => [ "=", "~", "!", "!~", "!*", "*" ],
:text => [ "~", "!~", "!*", "*" ],
:integer => [ "=", ">=", "<=", "><", "!*", "*" ],
:integer_done => [ "=", ">=", "<=", "><", "!*", "*" ],
:float => [ "=", ">=", "<=", "><", "!*", "*" ],
:relation => ["=", "=p", "=!p", "!p", "!*", "*"]
}
@ -217,6 +218,8 @@ class Query < ActiveRecord::Base
case type_for(field)
when :integer
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^[+-]?\d+$/) }
when :integer_done
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^[+-]?\d+$/) || (v.match(/^[+-]?\d+$/) && (v.to_i<0 || v.to_i> 100)) }
when :float
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^[+-]?\d+(\.\d*)?$/) }
when :date, :date_past
@ -602,6 +605,12 @@ class Query < ActiveRecord::Base
else
sql = "#{db_table}.#{db_field} = #{value.first.to_i}"
end
when :integer_done
if is_custom_filter
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) = #{value.first.to_i})"
else
sql = "#{db_table}.#{db_field} = #{value.first.to_i}"
end
when :float
if is_custom_filter
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})"