编辑代码

# true 请求参数,false 响应参数
isReq = true
str = ''

list = []
index = 0
current_obj=[]
strArr = str.split("\n")
strArr.each_with_index do |s, si|
    columnNum = isReq ? 4 : 3
	if index >= columnNum && s =~ /^[a-z]/
		index = 0
	end
	if index == 0 || strArr.length-1 == si
		list << current_obj if current_obj.length > 0
		current_obj = []
	end
	current_obj[index] = s
	index += 1
end
list.each do |data|
	puts "// #{data[1]} #{isReq ? (data[3] == '是' ? ',必填' : ',非必填') : ''} #{data[4,data.length].to_a.join("")}"
    fieldType = "unknown"
    fieldName = data[2].to_s
    if fieldName.start_with?("char") || fieldName.start_with?("varchar") || fieldName.start_with?("String")
        fieldType = "String"
    elsif fieldName.start_with?("bigint")
        fieldType = "Long"
    elsif fieldName.start_with?("int")
        fieldType = "Integer"
    elsif fieldName.start_with?("decimal")
        fieldType = "BigDecimal"
    elsif fieldName.start_with?("date")
        fieldType = "Date"
    end
	puts "private #{fieldType} #{data[0]};"
end