package cn.com.capcloud.core.noentitydb;

import cn.com.capcloud.core.websocket.RedisPublication;
import cn.com.capcloud.core.system.user.User;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.joda.time.DateTime;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;

import java.nio.charset.StandardCharsets;
import java.sql.Statement;
import java.util.*;


public class BaseDao {

	private static final Logger logger = LogManager.getLogger("LogFileAppSql");

	//分页查询
	public static JtPage getPageListAllCol(String tableName,String where,int page,int pageSize,JdbcTemplate jdbcTemplate){
		page++;
		String sql = "select * from " + tableName;
		if(where!=null) {
			sql+=" "+where;
		}
		 
		PageTool pageTool = new PageTool(sql, page, pageSize, jdbcTemplate);
		return pageTool.getJtPage();
	}
	//分页查询
		public static JtPage getPageListAllCol(String sql,int page,int pageSize,JdbcTemplate jdbcTemplate){
			page++;
			
			 
			PageTool pageTool = new PageTool(sql, page, pageSize, jdbcTemplate);
			return pageTool.getJtPage();
		}
	public static JtPage getPageListAllCol(String sql,int page,int pageSize,JdbcTemplate jdbcTemplate,String sqlCount){
		page++;


		PageTool pageTool = new PageTool(sql, page, pageSize, jdbcTemplate,sqlCount);
		return pageTool.getJtPage();
	}
	public static String getPkFieldName(String tableName,JdbcTemplate jdbcTemplate) {
		List<Map<String,Object>> mapList=BaseDao.getAllCommentsByTableName(tableName, jdbcTemplate);
		String pkFieldName="";
		for(int i=0;i<mapList.size();i++) {
			String key=String.valueOf(mapList.get(i).get("Key"));
			if(pkFieldName.equals("")&&key.length()>0&&key.equals("PRI")) {
				pkFieldName=String.valueOf(mapList.get(i).get("Field"));
			}
		}
		return pkFieldName;
	}
	//查询所有列信息
	public static List<Map<String,Object>> getAllCommentsByTableName(String tableName,JdbcTemplate jdbcTemplate) {
		if(DBCheck.isKingbase()){
			String sql="select column_name,data_type,character_maximum_length,'' as key from information_schema.columns where  table_name='"+tableName+"'  ";
			List<Map<String,Object>> mapList=jdbcTemplate.queryForList(sql);
			String pkFieldName=getPkFieldNameByTableName(tableName,jdbcTemplate);
			if(!pkFieldName.equals("")){
				for (int i = 0; i < mapList.size(); i++) {
					Map<String,Object> map=mapList.get(i);
					String columnName=String.valueOf(map.get("column_name"));
					if(pkFieldName.equals(columnName)){
						mapList.get(i).put("key","PRI");
						return mapList;
					}else{
						mapList.get(i).put("key","");
					}
				}
			}
			return mapList;
		}
		//默认执行的SQL，支持MySQL5.7/MySQL.8.0
		String sql="show full columns from "+tableName;
		List<Map<String,Object>> mapList=jdbcTemplate.queryForList(sql);
		return mapList;
	}
	//查询主键字段名
	public static String getPkFieldNameByTableName(String tableName,JdbcTemplate jdbcTemplate) {
		String sql=" SELECT tq.schema_name,\n" +
				"        tq.table_name,\n" +
				"        tq.index_name,\n" +
				"        tp.attname,\n" +
				"        tp.attnum,\n" +
				"        tq.amname,\n" +
				"        tz.description\n" +
				" FROM  sys_attribute tp INNER join\n" +
				"       (\n" +
				"        SELECT td.nspname schema_name, --schema name \n" +
				"        tc.relname table_name, -- table_name\n" +
				"        td.relname index_name, -- index_name\n" +
				"        UNNEST(indkey) attnum,\n" +
				"        tc.oid taboid ,-- table_id\n" +
				"        td.oid indexoid,\n" +
				"        tm.description,\n" +
				"        td.amname\n" +
				"        FROM sys_index ti \n" +
				"        INNER JOIN (SELECT tc.oid,\n" +
				"                           nspname , -- schema_name\n" +
				"                           relname -- table_name\n" +
				"                      FROM sys_class tc  \n" +
				"                      INNER JOIN sys_namespace  tn ON ( tc.relnamespace = tn.oid) \n" +
				"                      WHERE tc.relkind IN ('r','p')      AND   -- 表，分区表 \n" +
				"                            nspname = 'public'  --AND           -- schema\n" +
				"                            --relname = 'TBL_TEST001'\n" +
				"                            ) tc\n" +
				"                                    ON ( ti.indrelid = tc. oid )\n" +
				"          INNER JOIN (SELECT tc.oid,\n" +
				"                           nspname , -- schema_name\n" +
				"                           relname ,-- table_name\n" +
				"                           tc.relam,\n" +
				"                           ta.amname\n" +
				"                      FROM sys_class tc  \n" +
				"                      INNER JOIN sys_namespace  tn ON ( tc.relnamespace = tn.oid) \n" +
				"                      LEFT JOIN  sys_am  ta ON (tc.relam = ta.oid)\n" +
				"                      WHERE tc.relkind IN ('i','I')       AND   -- 表，分区表 \n" +
				"                            nspname = 'public' --AND           -- schema\n" +
				"                            --relname = 'TBL_TEST001'\n" +
				"                            ) td\n" +
				"        ON   (ti.indexrelid = td.oid)\n" +
				"        LEFT JOIN  sys_description tm\n" +
				"        ON (td.oid = tm.objoid)\n" +
				") tq\n" +
				"        ON (tp.attrelid =tq.taboid AND tp.attnum = tq.attnum )\n" +
				"        LEFT JOIN sys_description tz ON (  tz.objoid =tq.indexoid AND tz.objsubid = 0::oid )";
		List<Map<String,Object>> mapList=jdbcTemplate.queryForList(sql);
		for (int i = 0; i < mapList.size(); i++) {
			Map<String,Object> map=mapList.get(i);
			String pkTableName=String.valueOf(map.get("table_name"));
			if(pkTableName.equals(tableName)){
				return String.valueOf(map.get("attname"));
			}
		}
		return "";
	}
	//不分页查询
	public static List<Map<String,Object>> queryNotPage(String tableName,String where,JdbcTemplate jdbcTemplate){
		String sql = "select * from " + tableName + where; 
		return jdbcTemplate.queryForList(sql);
	}
	
	//单条更新
	public static Map<String,Object> updateOne(String tableName,JdbcTemplate jdbcTemplate,Map<String,Object> objMap){
		String sql="update "+tableName+" set ";
		List<Map<String,Object>> mapList=BaseDao.getAllCommentsByTableName(tableName, jdbcTemplate);
		String type="";
		String pkFieldName="";
		for(int i=0;i<mapList.size();i++) {
			if(objMap.get(String.valueOf(mapList.get(i).get("Field")))!=null){
				String key=String.valueOf(mapList.get(i).get("Key"));
				if(pkFieldName.equals("")&&key.length()>0&&key.equals("PRI")) {
					pkFieldName=String.valueOf(mapList.get(i).get("Field"));
				}else {
					type=String.valueOf(String.valueOf(mapList.get(i).get("Type")));
					boolean isdanyinhao=true;
					if(type.toLowerCase().indexOf("bit")>=0||type.toLowerCase().indexOf("int")>=0) {
	    				isdanyinhao=false;
	    			}
					if(isdanyinhao) {
						sql+="`"+mapList.get(i).get("Field")+"`='"+objMap.get(String.valueOf(mapList.get(i).get("Field")))+"',";
					}else {
						if(objMap.get(String.valueOf(mapList.get(i).get("Field")))==null||objMap.get(String.valueOf(mapList.get(i).get("Field"))).toString().length()==0) {
							sql+="`"+mapList.get(i).get("Field")+"`=0,";
						}else {
							sql+="`"+mapList.get(i).get("Field")+"`="+objMap.get(String.valueOf(mapList.get(i).get("Field")))+",";
						}
					}
				}
			}
		}
		sql=sql.substring(0,sql.length()-1);
		sql+=" where "+pkFieldName+"="+objMap.get(pkFieldName);
		logger.info(sql);
		jdbcTemplate.execute(sql);
		return objMap;
		
	}
	//批量保存
	public static Map<String,Object> saveBatch(String tableName, List<Map<String,Object>> objMaps, JdbcTemplate jdbcTemplate, RedisPublication redisPublication, String wsCode, User user) {
		Map<String,Object> retMap=new HashMap<>();
		String[] sqls=new String[objMaps.size()];
		if(redisPublication!=null)redisPublication.sendMessage("{\"wsCode\":\""+wsCode+"\",\"message\":\"开始检测数据是否规范...\",\"status\":\"ok\",\"isHideMask\":\"N\"}",String.valueOf(user.getId()));
		List<Map<String,Object>> mapList=BaseDao.getAllCommentsByTableName(tableName, jdbcTemplate);
		String insertSqlTemplate="insert into "+tableName+" (";
		Map<String,String> typeMap=new HashMap<String,String>();
		Map<String,Integer> widthMap=new HashMap<String,Integer>();
		List<Object> valueList=new ArrayList<Object>();
		Map<String,Object> objMap=objMaps.get(0);
		Integer textLength=65535;//text最大长度，超过这个长度请设置longtext
		String filedName="Field";
		String fieldType="Type";
		String fieldKey="Key";
		if(DBCheck.isKingbase()){
			filedName="column_name";
			fieldType="data_type";
			fieldKey="key";
		}
		String sqlChar= DBCheck.getIdentifierQuoteChar();
		for(int k=0;k<mapList.size();k++) {
			if(objMap.get(String.valueOf(mapList.get(k).get(filedName)))!=null){
				typeMap.put(String.valueOf(mapList.get(k).get(filedName)), String.valueOf(mapList.get(k).get(fieldType)));
				insertSqlTemplate+=""+sqlChar+mapList.get(k).get(filedName)+sqlChar+",";
				valueList.add(mapList.get(k).get(filedName));
				if(mapList.get(k).get(fieldType).toString().indexOf("(")>0) {
					String width=mapList.get(k).get(fieldType).toString();
					width=width.substring(width.indexOf("(")+1,width.indexOf(")"));
					widthMap.put(String.valueOf(mapList.get(k).get(filedName)), Integer.parseInt(width));
				}
				if(mapList.get(k).get(fieldType).toString().equals("text")){
					widthMap.put(String.valueOf(mapList.get(k).get(filedName)), textLength);
				}
			}
		}
		insertSqlTemplate=insertSqlTemplate.substring(0,insertSqlTemplate.length()-1);
		insertSqlTemplate+=") values (";
		for (int j = 0; j < objMaps.size(); j++) {
			objMap=objMaps.get(j);
			String sql=insertSqlTemplate;
			if(redisPublication!=null){
				if((j+1) % 500 == 0){
					redisPublication.sendMessage("{\"wsCode\":\""+wsCode+"\",\"message\":\"检测数据是否规范"+objMaps.size()+"条，当前检测到"+(j+1)+"条...\",\"status\":\"ok\",\"isHideMask\":\"N\"}",String.valueOf(user.getId()));
				}
			}
			for(int i=0;i<valueList.size();i++) {
				boolean isdanyinhao=true;
				if(typeMap.get(valueList.get(i)).toLowerCase().indexOf("bit")>=0||typeMap.get(valueList.get(i)).toLowerCase().indexOf("int")>=0) {
					isdanyinhao=false;
				}
				if(isdanyinhao) {
					sql+="'";
				}
				if(objMap.get(valueList.get(i))==null||objMap.get(valueList.get(i)).toString().length()==0) {
					if(isdanyinhao) {
						sql+="";
					}else{
						sql+="0";
					}
				}else {
					if(widthMap.get(valueList.get(i))!=null&&String.valueOf(objMap.get(valueList.get(i))).length()>=widthMap.get(valueList.get(i))){
						retMap.put("status","error");
						retMap.put("fieldName",valueList.get(i));
						retMap.put("fieldValue",objMap.get(valueList.get(i)));
						retMap.put("maxLength",widthMap.get(valueList.get(i)));
						retMap.put("fieldLength",String.valueOf(objMap.get(valueList.get(i))).length());
						return retMap;
					}
					if(widthMap.get(valueList.get(i))!=null&&String.valueOf(widthMap.get(valueList.get(i))).equals(textLength+"")){
						Integer strLength=String.valueOf(objMap.get(valueList.get(i))).getBytes(StandardCharsets.UTF_8).length;
						if(strLength>=textLength){
							retMap.put("status","error");
							retMap.put("fieldName",valueList.get(i));
							retMap.put("fieldValue",objMap.get(valueList.get(i)));
							retMap.put("maxLength",widthMap.get(valueList.get(i)));
							retMap.put("fieldLength",strLength);
							return retMap;
						}
					}
					String value=String.valueOf(objMap.get(valueList.get(i)));
					if(value.endsWith("\\")){
						value+="\\";
					}
					value=value.replaceAll("\'","&quot;");
					sql+=value;
				}
				if(isdanyinhao) {
					sql+="',";
				}else {
					sql+=",";
				}
			}
			sql=sql.substring(0,sql.length()-1);
			sql+=")";
			if(j==0)logger.info("#####"+sql);
			sqls[j]=sql;
		}
		if(redisPublication!=null){
			redisPublication.sendMessage("{\"wsCode\":\""+wsCode+"\",\"message\":\"检测通过，开始执行入库...\",\"status\":\"ok\",\"isHideMask\":\"N\"}",String.valueOf(user.getId()));
		}
		for (int i = 0; i < sqls.length; i++) {
			if(redisPublication!=null&&(i+1) % 100 == 0){
				redisPublication.sendMessage("{\"wsCode\":\""+wsCode+"\",\"message\":\"正在入库，总："+objMaps.size()+" 条，已入库："+(i+1)+" 条...\",\"status\":\"ok\",\"isHideMask\":\"N\"}",String.valueOf(user.getId()));
			}
			jdbcTemplate.execute(sqls[i]);
		}
		//jdbcTemplate.batchUpdate(sqls);
		retMap.put("status","ok");
		return retMap;
	}
	//批量更新
	public static List<Map<String,Object>> updateBatch(String tableName,JdbcTemplate jdbcTemplate,List<Map<String,Object>> objMaps){
		List<Map<String,Object>> mapList=BaseDao.getAllCommentsByTableName(tableName, jdbcTemplate);
		String filedName="Field";
		String fieldType="Type";
		String fieldKey="Key";
		if(DBCheck.isKingbase()){
			filedName="column_name";
			fieldType="data_type";
			fieldKey="key";
		}
		String sqlChar= DBCheck.getIdentifierQuoteChar();
		String type="";
		String pkFieldName="";
		String[] sqls=new String[objMaps.size()];
		for (int j = 0; j < objMaps.size(); j++) {
			Map<String,Object> objMap=objMaps.get(j);
			String sql="update "+tableName+" set ";
			for(int i=0;i<mapList.size();i++) {
				if(objMap.get(String.valueOf(mapList.get(i).get(filedName)))!=null){
					String key=String.valueOf(mapList.get(i).get(fieldKey));
					if(pkFieldName.equals("")&&key.length()>0&&key.equals("PRI")) {
						pkFieldName=String.valueOf(mapList.get(i).get(filedName));
					}else {
						type=String.valueOf(String.valueOf(mapList.get(i).get(fieldType)));
						boolean isdanyinhao=true;
						if(DBCheck.isKingbase()){
							if(type.toLowerCase().indexOf("integer")>=0||type.toLowerCase().indexOf("int")>=0||type.toLowerCase().indexOf("bigint")>=0) {
								isdanyinhao=false;
							}
						}else{
							if(type.toLowerCase().indexOf("bit")>=0||type.toLowerCase().indexOf("int")>=0) {
								isdanyinhao=false;
							}
						}
						if(isdanyinhao) {
							sql+=""+sqlChar+mapList.get(i).get(filedName)+sqlChar+"='"+objMap.get(String.valueOf(mapList.get(i).get(filedName)))+"',";
						}else {
							if(objMap.get(String.valueOf(mapList.get(i).get(filedName)))==null||objMap.get(String.valueOf(mapList.get(i).get(filedName))).toString().length()==0) {
								sql+=""+sqlChar+mapList.get(i).get(filedName)+sqlChar+"=0,";
							}else {
								sql+=""+sqlChar+mapList.get(i).get(filedName)+sqlChar+"="+objMap.get(String.valueOf(mapList.get(i).get(filedName)))+",";
							}
						}
					}
				}
			}
			sql=sql.substring(0,sql.length()-1);
			sql+=" where "+pkFieldName+"='"+objMap.get(pkFieldName)+"'";
			sqls[j]=sql;
		}
		jdbcTemplate.batchUpdate(sqls);
		return objMaps;
	}
	//单条查询
	public static Map<String,Object> findOne(String tableName,String pkId,JdbcTemplate jdbcTemplate){
		List<Map<String,Object>> mapList=BaseDao.getAllCommentsByTableName(tableName, jdbcTemplate);
		String sql="select ";
		String pkIdType="long";
		String pkIdName=BaseDao.getPkFieldName(tableName, jdbcTemplate);
		for(int i=0;i<mapList.size();i++) {
			if(pkIdName.equals(String.valueOf(mapList.get(i).get("Field")))) {
				if(String.valueOf(mapList.get(i).get("Type")).indexOf("varchar")>=0) {
					pkIdType="String";
				}
			}
			if(i==mapList.size()-1) {
				sql+=String.valueOf(mapList.get(i).get("Field"));
			}else {
				sql+=mapList.get(i).get("Field")+",";
			}
		}
		sql+=" from "+tableName+" where "+pkIdName+"=";
		if(pkIdType.equals("long")) {
			sql+=pkId;
		}else {
			sql+="'"+pkId+"'";
		}
		logger.info(sql);
		List<Map<String,Object>> resultMapList=jdbcTemplate.queryForList(sql);
		
		Map<String,Object> resultMap=new HashMap<String,Object>();
		if(resultMapList.size()>0) {
			resultMap=resultMapList.get(0);
		}
		return resultMap;
	}
	public static Map<String,Object> findOne(String tableName,String pkId,JdbcTemplate jdbcTemplate,String pkFileId){
		String sql="select *";
		sql+=" from "+tableName+" where "+pkFileId+"=";
		sql+="'"+pkId+"'";
		List<Map<String,Object>> resultMapList=jdbcTemplate.queryForList(sql);

		Map<String,Object> resultMap=new HashMap<String,Object>();
		if(resultMapList.size()>0) {
			resultMap=resultMapList.get(0);
		}
		return resultMap;
	}
	//有long型主键增加
	public static long addForLongPkId(String tableName,Map<String,Object> objMap,JdbcTemplate jdbcTemplate) {
		 KeyHolder keyHolder = new GeneratedKeyHolder();
	        PreparedStatementCreator preparedStatementCreator = con -> {
	        	String sql="insert into "+tableName+" (";
	    		List<Map<String,Object>> mapList=BaseDao.getAllCommentsByTableName(tableName, jdbcTemplate);
	    		Map<String,String> typeMap=new HashMap<String,String>();
	    		List<Object> valueList=new ArrayList<Object>();
	    		String filedName="Field";
	    		String fieldType="Type";
				if(DBCheck.isKingbase()){
					filedName="column_name";
					fieldType="data_type";
				}
				String sqlChar= DBCheck.getIdentifierQuoteChar();
	    		for(int i=0;i<mapList.size();i++) {
	    			if(objMap.get(String.valueOf(mapList.get(i).get(filedName)))!=null){
	    				typeMap.put(String.valueOf(mapList.get(i).get(filedName)), String.valueOf(mapList.get(i).get(fieldType)));
						sql+=""+sqlChar+mapList.get(i).get(filedName)+sqlChar+",";

						valueList.add(mapList.get(i).get(filedName));
	    			}
	    		}
	    		sql=sql.substring(0,sql.length()-1);
	    		sql+=") values (";
	    		for(int i=0;i<valueList.size();i++) {
	    			boolean isdanyinhao=true;
	    			if(typeMap.get(valueList.get(i)).toLowerCase().indexOf("bit")>=0||typeMap.get(valueList.get(i)).toLowerCase().indexOf("int")>=0) {
	    				isdanyinhao=false;
	    			}
					if(isdanyinhao) {
						sql+="'";
					}
					if(objMap.get(valueList.get(i))==null||objMap.get(valueList.get(i)).toString().length()==0) {
						if(isdanyinhao) {
							sql+="";
						}else{
							sql+="0";
						}
					}else {
						String value=String.valueOf(objMap.get(valueList.get(i)));
						value=value.replaceAll("\'","&quot;");
						sql+=value;
					}
					if(isdanyinhao) {
						sql+="',";
					}else {
						sql+=",";
					}
	    		}
				sql=sql.substring(0,sql.length()-1);
				sql+=")";
				logger.info("#####"+sql);
	            java.sql.PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
	            return ps;
	        };
	        jdbcTemplate.update(preparedStatementCreator, keyHolder);
		try {
			keyHolder.getKey().longValue();
		} catch (Exception e) {
			return -1;
		}
		return keyHolder.getKey().longValue();
	}
	//无主键增加
	public static void add(String tableName,Map<String,Object> objMap,JdbcTemplate jdbcTemplate) {
		String sql="insert into "+tableName+" (";
		List<Map<String,Object>> mapList=BaseDao.getAllCommentsByTableName(tableName, jdbcTemplate);
		Map<String,String> typeMap=new HashMap<String,String>();
		List<Object> valueList=new ArrayList<Object>();
		for(int i=0;i<mapList.size();i++) {
			if(objMap.get(String.valueOf(mapList.get(i).get("Field")))!=null){
				typeMap.put(String.valueOf(mapList.get(i).get("Field")), String.valueOf(mapList.get(i).get("Type")));
				if(i<mapList.size()-1) {
					sql+=mapList.get(i).get("Field")+",";
				}else {
					sql+=mapList.get(i).get("Field")+") values (";
				}
				valueList.add(mapList.get(i).get("Field"));
			}
		}
		for(int i=0;i<valueList.size();i++) {
			boolean isdanyinhao=true;
			if(typeMap.get(valueList.get(i)).toLowerCase().indexOf("int")>=0) {
				isdanyinhao=false;
			}
			if(i<valueList.size()-1) {
				if(isdanyinhao) {
					sql+="'";
				}
				sql+=objMap.get(valueList.get(i));
				if(isdanyinhao) {
					sql+="',";
				}else {
					sql+=",";
				}
			}else {
				sql+="'"+objMap.get(valueList.get(i))+"')";
			}
		}
		System.out.println(sql);
		jdbcTemplate.execute(sql);
	}
	//set save 一些默认值
	public static void setDefaultValue(Map<String,Object> dataMap,User user){
		DateTime d = new DateTime();
		String status=String.valueOf(dataMap.get("status"));
		String time=d.toString("yyyy-MM-dd HH:mm:ss");
		String date=d.toString("yyyy-MM-dd");
		if("null".equals(status)||status.length()==0){
			dataMap.put("status","0");
		}
		String createTime=String.valueOf(dataMap.get("create_time"));
		if("null".equals(createTime)||createTime.length()==0){
			dataMap.put("create_time", time);
		}
		if("null".equals(createTime)||createTime.length()==0){
			dataMap.put("create_date", date);
		}
		if("null".equals(createTime)||createTime.length()==0){
			dataMap.put("update_time", time);
		}
		if("null".equals(createTime)||createTime.length()==0){
			dataMap.put("update_date", date);
		}
		String uuid=String.valueOf(dataMap.get("uuid"));
		if("null".equals(uuid)||uuid.length()==0){
			dataMap.put("uuid", UUID.randomUUID().toString().replaceAll("-",""));
		}
		if(user!=null){
			dataMap.put("create_user_id",user.getId());
			dataMap.put("create_org_id",user.getOrgId());
			dataMap.put("create_org_name",user.getOrgName());
			dataMap.put("create_user",user.getUserName());
		}else{
			String createUserId=String.valueOf(dataMap.get("create_user_id"));
			if("null".equals(createUserId)||createUserId.length()==0){
				dataMap.put("create_user_id","");
			}
			String createOrgId=String.valueOf(dataMap.get("create_org_id"));
			if("null".equals(createOrgId)||createOrgId.length()==0){
				dataMap.put("create_org_id","");
			}
			String createOrgName=String.valueOf(dataMap.get("create_org_name"));
			if("null".equals(createOrgName)||createOrgName.length()==0){
				dataMap.put("create_org_name","");
			}
			String createUser=String.valueOf(dataMap.get("create_user"));
			if("null".equals(createUser)||createUser.length()==0){
				dataMap.put("create_user","");
			}
		}
	}

	//set update 一些默认值
	public static void setUpdateDefaultValue(Map<String,Object> dataMap,User user){
		DateTime d = new DateTime();
		String time=d.toString("yyyy-MM-dd HH:mm:ss");
		String date=d.toString("yyyy-MM-dd");
		String createTime=String.valueOf(dataMap.get("update_time"));
		if("null".equals(createTime)||createTime.length()==0){
			dataMap.put("update_time", time);
		}
		if("null".equals(createTime)||createTime.length()==0){
			dataMap.put("update_date", date);
		}
		if(user!=null){
			dataMap.put("update_user",user.getUserName());
		}
	}


}
