package com.util;

import java.util.List;

public class AutoDtoFile {
	public static boolean creatDtoFile(String sqlTableName,String title,List list){
		if(null==title){
			title="";
		}
		String tableName=UtilTools.szmZdx(sqlTableName);
		StringBuffer buf=new StringBuffer();
		buf.append("package com.cn.pojo;\r\n"+
				    "import javax.persistence.Column;\r\n"+
					"import javax.persistence.Entity;\r\n"+
					"import javax.persistence.Id;\r\n"+
					"import javax.persistence.Table;\r\n"+
				    "import com.dubh.common.dto.BaseDto;\r\n\r\n" +
				    "/**\r\n"+
					" * "+title+"\r\n"+
					" * @author zengwp\r\n"+
					" */\r\n"+
					" @Entity\r\n"+
					" @Table(name = \""+sqlTableName+"\")\r\n"+
					" public class "+tableName+" extends BaseDto {\r\n"+
					" \r\n");
		//生成字段变量
		for (int i = 0; i <list.size(); i++) {
			Object[] arr=(Object[])list.get(i);
			String strSty="String ";
			if(arr[1].toString().indexOf("int")>=0){
				strSty="Integer ";
			}
			buf.append("\t private "+strSty+arr[0]+";\r\n");
		}
		
		//默认第一个为主键
		buf.append("\r\n\t @Id\r\n");
		
		//GET和SET方法
		for (int i = 0; i < list.size(); i++) {
			Object[] arr=(Object[])list.get(i);
			String strSty="String ";
			if(arr[1].toString().indexOf("int")>=0){
				strSty="Integer ";
			}
			String optsName=UtilTools.szmZdx(arr[0].toString());
			buf.append("\t @Column(name = \""+arr[0]+"\")\r\n");
			buf.append("\t public "+strSty+" get"+optsName+"() {\r\n"+
			"\t	return "+arr[0]+";\r\n"+
			"\t  }\r\n"+
			"\t public void set"+optsName+"("+strSty+" "+arr[0]+") {\r\n"+
			"\t 	this."+arr[0]+" = "+arr[0]+";\r\n"+
			"\t }\r\n");
		}
		buf.append(" }");
		return NewFieldUtileTools.fileOperation("E:\\WorkSpace\\goldkey\\src\\com\\cn\\pojo",tableName+".java",buf.toString());
		
	}
}
