package ncc.impl.arap.report;

import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import nc.bs.dao.BaseDAO;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.pub.smart.context.SmartContext;
import nc.pub.smart.data.DataSet;
import nc.pub.smart.metadata.Field;
import nc.pub.smart.metadata.MetaData;
import nc.uap.bd.util.BDInSqlUtil;
import nc.vo.bd.cashflow.CashflowVO;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.bd.fundplan.FundPlanVO;
import nc.vo.bd.inoutbusiclass.InoutBusiClassVO;
import nc.vo.jcom.lang.StringUtil;
import nc.vo.org.FundOrgVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.JavaType;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pub.query.ConditionVO;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.vorg.OrgVersionVO;
import ncc.itf.arap.report.IInternalTransferInfo;

public class InternalTransferInfoImpl implements IInternalTransferInfo {

	@Override
	public DataSet queryInternalTransferInfoReport(SmartContext context) throws BusinessException {
		
		
		ConditionVO[] conditionVOs = (ConditionVO[])context.getAttribute("freereport_querycondition_vos");
		List<ConditionVO> whereList = conditionVOs!= null ? Arrays.asList(conditionVOs) : new ArrayList<>(0);
		Map<String, String> whereMap = whereList.stream().collect(Collectors.toMap(ConditionVO::getFieldCode, ConditionVO::getValue));
		
		MetaData meta = new MetaData();
		BaseDAO dao = new BaseDAO();
		
		Map<String, String> map = new LinkedHashMap<>();
		map.put("gqqk","股权情况");
		map.put("ssbk","所属板块");
		map.put("ssqy","所属区域");
		map.put("ywlx","业务类型");
		map.put("gsbm","公司编码");
		map.put("gsmc","公司名称");
		map.put("sfzjzx","收方资金中心");
		map.put("ffzjzx","付方资金中心");
		map.put("djlx","单据类型");
		map.put("djrq","单据日期");
		map.put("djzt","单据状态");
		map.put("jsrq","结算日期");
		map.put("jszt","结算状态");
		map.put("yhzh","银行帐号");
		map.put("zy","摘要");
		map.put("djbh","单据编号");
		map.put("nccszxm","NCC收支项目");
		map.put("nccjhxm","NCC资金计划项目");
		map.put("nccxjllxm","NCC现金流量项目");
		map.put("nc63szxm","NC63收支项目");
		map.put("nc63jhxm","NC63资金计划项目");
		map.put("nc63xjllxm","NC63现金流量项目");
		map.put("bbsr","本币收入");
		map.put("bbzc","本币支出");
		map.put("ybsr","原币收入");
		map.put("ybzc","原币支出");
		map.put("sfkqy","是否跨区域");
		
		String[] fldnames = map.keySet().toArray(new String[0]);
		String[] captions = map.values().toArray(new String[0]);
		
		Integer[] ilengths = new Integer[] { 300};
		JavaType[] types = new JavaType[] { JavaType.String };
		for (int i = 0; i < captions.length; i++) {
			Field field = new Field();
			field.setCaption(captions[i]);
			field.setFldname(fldnames[i]);
			setFieldByType(field, types[0], ilengths[0]);
			meta.addField(field);
		}
		
		//有必输条件时生效
		if(whereMap.isEmpty()) {
			return new DataSet(meta, new Object[0][0]);
		}
		
		StringBuilder sql = new StringBuilder();
		sql.append( "select distinct * from ( \r\n" + 
				"\r\n" + 
				"select skd.def19 as gqqk,skd.def17 as ssbk,skd.def16 as ssqy,skd.def13 as ywlx,skd.pk_org_v as gsbm,skd.pk_org_v as gsmc,skd.def4 as sfzjzx,skd.def21 as ffzjzx,"
//				+ "skd.pk_tradetype as djlx,\r\n" +
				+ "'收款单（内转	）' as djlx,\r\n" +
				"skd.billdate as djrq,skd.billstatus as djzt,jsd.settledate as jsrq,jsd.settlestatus as jszt,acc.accnum as yhzh,skdmx.scomment as zy,skd.billno as djbh,szxm.pk_inoutbusiclass as nccszxm,\r\n" + 
				"skdmx.bankrollprojet as nccjhxm,skdmx.cashitem as nccxjllxm,skdmx.def31 as nc63szxm ,skdmx.def42 as nc63jhxm,skdmx.def33 as nc63xjllxm,\r\n" + 
				"skdmx.local_money_cr as bbsr,0.00 as bbzc,skdmx.money_cr as ybsr,0.00 as ybzc,case when skd.def7='Y' then '是' else '否' end  as sfkqy \r\n" + 
				"\r\n" + 
				"from ar_gatherbill skd \r\n" + 
				"left join (select * from (select pk_gatherbill,pk_subjcode,money_cr,local_money_cr,def33,def42,def31,cashitem,bankrollprojet,scomment,row_number() over(partition by pk_gatherbill order by pk_gatherbill asc )  rn_01  from ar_gatheritem where nvl( dr, 0 ) = 0) where rn_01 = 1) skdmx on skdmx.pk_gatherbill=skd.pk_gatherbill\r\n" + 
				"left join cmp_settlement jsd on skd.pk_gatherbill=jsd.pk_busibill and jsd.dr=0 \r\n" + 
				"left join cmp_detail jsdmx on jsdmx.pk_settlement=jsd.pk_settlement\r\n" + 
				"\r\n" + 
				"left outer join bd_inoutbusiclass szxm on skdmx.pk_subjcode= szxm.pk_inoutbusiclass\r\n" + 
				"left outer join bd_bankaccsub acc on acc.pk_bankaccbas=jsdmx.pk_account\r\n" + 
//				"left join org_orgs_v orgv on orgv.pk_vid=skd.pk_org_v\r\n" + 
				"\r\n" + 
//				" where skd.pk_billtype='F2' and skd.billdate>'2022-04-22'\r\n" +
				" where skd.pk_tradetype='F2-Cxx-01'"
				+ " and  nvl( skd.dr, 0 ) = 0 "
//				+ " and  nvl( skdmx.dr, 0 ) = 0 "
//				+ " and  nvl( jsd.dr, 0 ) = 0 "
//				+ " and  nvl( jsdmx.dr, 0 ) = 0 "
//				+ " and  nvl( szxm.dr, 0 ) = 0 "
//				+ " and  nvl( acc.dr, 0 ) = 0 "
				+ ""
				+ ""
				+ " \r\n" +
				" \r\n" + 
				" union all\r\n" + 
				" \r\n" + 
				" select fkd.def9 as gqqk,fkd.def8 as ssbk,fkd.def6 as ssqy,fkd.def77 as ywlx,fkd.pk_org_v as gsbm,fkd.pk_org_v as gsmc,fkd.def4 as sfzjzx,fkd.def18 as ffzjzx,"
//				+ "fkd.pk_tradetype as djlx,\r\n" +
				+ "'付款单（内转）' as djlx,\r\n" +
				" fkd.billdate as djrq,fkd.billstatus as djzt,jsd.settledate as jsrq,jsd.settlestatus as jszt,acc.accnum as yhzh,fkdmx.scomment as zy,fkd.billno as djbh,szxm.pk_inoutbusiclass as nccszxm,\r\n" + 
				"fkdmx.bankrollprojet as nccjhxm,fkdmx.cashitem as nccxjllxm,fkdmx.def41 as nc63szxm,fkdmx.def42 as nc63jhxm,fkdmx.def43 as nc63xjllxm,\r\n" + 
				"0.00 as bbsr,fkdmx.local_money_de as bbzc,0.00 as ybsr,fkdmx.money_de as ybzc,case when fkd.def7='Y' then '是' else '否' end  as sfkqy\r\n" + 
				" \r\n" + 
				" from ap_paybill fkd \r\n" + 
				" left join  (select * from ( select scomment,bankrollprojet,cashitem,def41,def42,def43,local_money_de,money_de,pk_paybill,pk_subjcode,row_number() over(partition by pk_paybill order by pk_paybill asc )  rn_01  from ap_payitem  where nvl( dr, 0 ) = 0 ) where rn_01=1) fkdmx on fkd.pk_paybill=fkdmx.pk_paybill\r\n" + 
				" left join cmp_settlement jsd on fkd.pk_paybill=jsd.pk_busibill and jsd.dr=0 \r\n" + 
				"left join cmp_detail jsdmx on jsdmx.pk_settlement=jsd.pk_settlement\r\n" + 
				"\r\n" + 
				"left outer join bd_inoutbusiclass szxm on fkdmx.pk_subjcode= szxm.pk_inoutbusiclass\r\n" + 
				"left outer join bd_bankaccsub acc on acc.pk_bankaccbas=jsdmx.pk_account\r\n" + 
//				"left join org_orgs_v orgv on orgv.pk_vid=fkd.pk_org_v\r\n" + 
				"\r\n" + 
//				"where fkd.pk_billtype='F3' and fkd.billdate>'2022-04-22'\r\n" +
				"where fkd.pk_tradetype='F3-Cxx-D01'" +
				" and  nvl( fkd.dr, 0 ) = 0 " +
//				" and  nvl( fkdmx.dr, 0 ) = 0 " +
//				" and  nvl( jsd.dr, 0 ) = 0 " +
//				" and  nvl( jsdmx.dr, 0 ) = 0 " +
//				" and  nvl( szxm.dr, 0 ) = 0 " +
//				" and  nvl( acc.dr, 0 ) = 0 " +
				" \r\n" + 
				" ) t1 where 1=1");
		
		joinMustSqlWhere(sql, whereMap);
		
		List<Map<String, Object>> qryRetList = (List<Map<String, Object>>) dao.executeQuery(sql.toString(), new MapListProcessor());
		
		List<String> gqqkList = new LinkedList<>();
		List<String> ssbkList = new LinkedList<>();
		List<String> ssqyList = new LinkedList<>();
		List<String> ywlxList = new LinkedList<>();
		List<String> zjzxList = new LinkedList<>();
		List<String> nccSzxmList = new LinkedList<>();
		List<String> nccjhxmList = new LinkedList<>();
		List<String> nccxjllxmList = new LinkedList<>();
		List<String> nc63szxmList = new LinkedList<>();
		List<String> org_org_v_pk = new LinkedList<>();
		
		
		for(Map<String, Object> itemMap : qryRetList) {
			gqqkList.add((String)itemMap.get("gqqk"));
			ssbkList.add((String)itemMap.get("ssbk"));
			ssqyList.add((String)itemMap.get("ssqy"));
			ywlxList.add((String)itemMap.get("ywlx"));
			zjzxList.add((String)itemMap.get("ffzjzx"));
			zjzxList.add((String)itemMap.get("sfzjzx"));
			nccSzxmList.add((String)itemMap.get("nccszxm"));
			nccjhxmList.add((String)itemMap.get("nccjhxm"));
			
			nccxjllxmList.add((String)itemMap.get("nccxjllxm"));
			nccxjllxmList.add((String)itemMap.get("nc63xjllxm"));
			
			nc63szxmList.add((String)itemMap.get("nc63szxm"));
			nc63szxmList.add((String)itemMap.get("nc63jhxm"));
			org_org_v_pk.add((String)itemMap.get("gsmc"));
			
		}
		
		gqqkList = gqqkList.stream().distinct().collect(Collectors.toList());
		ssbkList = ssbkList.stream().distinct().collect(Collectors.toList());
		ssqyList = ssqyList.stream().distinct().collect(Collectors.toList());
		ywlxList = ywlxList.stream().distinct().collect(Collectors.toList());
		zjzxList = zjzxList.stream().distinct().collect(Collectors.toList());
		nccSzxmList = nccSzxmList.stream().distinct().collect(Collectors.toList());
		nccjhxmList = nccjhxmList.stream().distinct().collect(Collectors.toList());
		nccxjllxmList = nccxjllxmList.stream().distinct().collect(Collectors.toList());
		nc63szxmList = nc63szxmList.stream().distinct().collect(Collectors.toList());
		org_org_v_pk= org_org_v_pk.stream().distinct().collect(Collectors.toList());
		
		Map<String, DefdocVO> gqqkDefDocVOMap =  (Map<String, DefdocVO>) dao.retrieveByClause(DefdocVO.class, " pk_defdoc in " + BDInSqlUtil.getInSql(gqqkList.toArray(new String[0]), false)).stream().collect(Collectors.toMap(DefdocVO::getPk_defdoc, item -> item ));
		
		Map<String, DefdocVO>  ssbkDefDocVOMap =  (Map<String, DefdocVO>) dao.retrieveByClause(DefdocVO.class, " pk_defdoc in " + BDInSqlUtil.getInSql(ssbkList.toArray(new String[0]), false)).stream().collect(Collectors.toMap(DefdocVO::getPk_defdoc, item -> item ));
		
		Map<String, DefdocVO> ssqyDefDocVOMap =  (Map<String, DefdocVO>) dao.retrieveByClause(DefdocVO.class, " pk_defdoc in " + BDInSqlUtil.getInSql(ssqyList.toArray(new String[0]), false)).stream().collect(Collectors.toMap(DefdocVO::getPk_defdoc, item -> item ));
		
		Map<String, DefdocVO> ywlxDefDocVOMap =  (Map<String, DefdocVO>) dao.retrieveByClause(DefdocVO.class, " pk_defdoc in " + BDInSqlUtil.getInSql(ywlxList.toArray(new String[0]), false)).stream().collect(Collectors.toMap(DefdocVO::getPk_defdoc, item -> item ));
		
		Map<String, DefdocVO> nc63szxmDefDocVOMap =  (Map<String, DefdocVO>) dao.retrieveByClause(DefdocVO.class, " pk_defdoc in " + BDInSqlUtil.getInSql(nc63szxmList.toArray(new String[0]), false)).stream().collect(Collectors.toMap(DefdocVO::getPk_defdoc, item -> item ));
		
		Map<String, FundOrgVO>  fundOrgVOcVOMap =  (Map<String, FundOrgVO>) dao.retrieveByClause(FundOrgVO.class, " pk_fundorg in " + BDInSqlUtil.getInSql(zjzxList.toArray(new String[0]), false)).stream().collect(Collectors.toMap(FundOrgVO::getPk_fundorg, item -> item ));
		
		Map<String, InoutBusiClassVO>  nccSzxmVOMap =  (Map<String, InoutBusiClassVO>) dao.retrieveByClause(InoutBusiClassVO.class, " pk_inoutbusiclass in " + BDInSqlUtil.getInSql(nccSzxmList.toArray(new String[0]), false)).stream().collect(Collectors.toMap(InoutBusiClassVO::getPk_inoutbusiclass, item -> item ));
		
		Map<String, FundPlanVO>  nccJhxmVOMap =  (Map<String, FundPlanVO>) dao.retrieveByClause(FundPlanVO.class, " pk_fundplan in " + BDInSqlUtil.getInSql(nccjhxmList.toArray(new String[0]), false)).stream().collect(Collectors.toMap(FundPlanVO::getPk_fundplan, item -> item ));
		
		Map<String, CashflowVO>  nccxjllxmVOMap =  (Map<String, CashflowVO>) dao.retrieveByClause(CashflowVO.class, " pk_cashflow in " + BDInSqlUtil.getInSql(nccxjllxmList.toArray(new String[0]), false)).stream().collect(Collectors.toMap(CashflowVO::getPk_cashflow, item -> item ));
		
		Map<String, OrgVersionVO>  orgvVOMap =  (Map<String, OrgVersionVO>) dao.retrieveByClause(OrgVersionVO.class, " pk_vid in " + BDInSqlUtil.getInSql(org_org_v_pk.toArray(new String[0]), false)).stream().collect(Collectors.toMap(OrgVersionVO::getPk_vid, item -> item ));
		
		
		List<Object[]> list = new LinkedList<>();	
		for (Map<String, Object> itemMap : qryRetList) {
			Object[] data = new Object[map.size()];
			int i = -1; 
			for(String field : fldnames) {
				i++;
				Object obj = itemMap.get(field);
				
				if("gqqk".equals(field)) {
					DefdocVO vo = gqqkDefDocVOMap.get( obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				if("ssbk".equals(field)) {
					DefdocVO vo = ssbkDefDocVOMap.get( obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				if("ssqy".equals(field)) {
					DefdocVO vo = ssqyDefDocVOMap.get( obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				if("ywlx".equals(field)) {
					DefdocVO vo = ywlxDefDocVOMap.get( obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				if("ffzjzx".equals(field)) {
					FundOrgVO vo = fundOrgVOcVOMap.get(obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				
				if("sfzjzx".equals(field)) {
					FundOrgVO vo = fundOrgVOcVOMap.get(obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				
				
				if("nccszxm".equals(field)) {
					InoutBusiClassVO vo = nccSzxmVOMap.get(obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				
				if("nccjhxm".equals(field)) {
					FundPlanVO vo = nccJhxmVOMap.get(obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				if("nccxjllxm".equals(field) || "nc63xjllxm".equals(field)) {
					CashflowVO vo = nccxjllxmVOMap.get(obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				if("nc63szxm".equals(field) || "nc63jhxm".equals(field)) {
					DefdocVO vo = nc63szxmDefDocVOMap.get(obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				
				if("gsmc".equals(field)) {
					OrgVersionVO vo = orgvVOMap.get(obj);
					data[i] = null != vo ? vo.getName() : null;
					continue;
				}
				if("gsbm".equals(field)) {
					OrgVersionVO vo = orgvVOMap.get(obj);
					data[i] = null != vo ? vo.getCode() : null;
					continue;
				}
				
				
				if("djzt".equals(field) && null != obj) {
					//保存=-1,暂存=-99,审批通过=1,签字=8,未确认=9
					String content = null;
					if(new Integer(-1).equals(obj)) {
						content = "保存";
					}
					if(new Integer(-99).equals(obj)) {
						content = "暂存";
					}
					if(new Integer(1).equals(obj)) {
						content = "审批通过";
					}
					if(new Integer(8).equals(obj)) {
						content = "签字";
					}
					if(new Integer(9).equals(obj)) {
						content = "签字";
					}
					data[i] =  content;
					continue;
				}
				
				if("jszt".equals(field) && null != obj) {
					//0=未结算;1=支付中;2=支付失败;3=收款中;4=收款失败;5=结算成功;6=部分成功;7=结算红冲;9=手工结算;10=划账中;11=划账失败;12=待变更;
					String content = null;
				
					Integer val = (Integer)obj; 
					
					switch(val) {
					 case 0 :
						 content="未结算";
						 break;
					 case 1 :
						 content="支付中";
						 break;
					 case 2 :
						 content="支付失败";
						 break;
					 case 3 :
						 content="首款中";
						 break;
					 case 4 :
						 content="收款失败";
						 break;
					 case 5 :
						 content="结算成功";
						 break;
					 case 6 :
						 content="部分成功";
						 break;
					 case 7 :
						 content="手工结算";
						 break;
					 case 10 :
						 content="划账中";
						 break;
					 case 11 :
						 content="划账失败";
						 break;
					 case 12 :
						 content="待变更";
						 break;
					
					}
					data[i] =  content;
					continue;
				}
				
				if(null != obj && ("bbsr".equals(field) || "bbzc".equals(field) || "ybsr".equals(field) || "ybzc".equals(field))) {
					UFDouble numberTemp = new UFDouble(obj.toString(), 2);
					data[i] =  numberTemp.toString();
					continue;
				}
				
				
				data[i] =  null != obj ? (   obj instanceof java.lang.String ? (obj.toString().length() > 250  ? obj.toString().substring(0, 240)+"..."  : obj)  :  obj ) : null ;	
				
			}
			list.add(data);
			
		}
		
		Object[][] datas = new Object[qryRetList.size()][map.size()];
		
		for(int i = 0; i < qryRetList.size(); i++ ) {
			datas[i] = list.get(i);
		}

		DataSet ds = new DataSet(meta, datas);
		
		return ds;
	}
	
	public void joinMustSqlWhere(final StringBuilder sql, final Map<String, String> whereMap) {
	
		String sfzjzx = whereMap.get("sfzjzx");
		if(!StringUtil.isEmptyWithTrim(sfzjzx)) {
			sql.append(" and sfzjzx in "+sfzjzx);
		}

		String ffzjzx = whereMap.get("ffzjzx");
		if(!StringUtil.isEmptyWithTrim(ffzjzx)) {
			sql.append(" and ffzjzx in "+ffzjzx);
		}
		
		String gqqk = whereMap.get("gqqk");
		if(!StringUtil.isEmptyWithTrim(gqqk)) {
			sql.append(" and gqqk = '"+gqqk+"' ");
		}
		
		String ywlx = whereMap.get("ywlx");
		if(!StringUtil.isEmptyWithTrim(ywlx)) {
			sql.append(" and ywlx = '"+ywlx+"' ");
		}
		String ssbk = whereMap.get("ssbk");
		if(!StringUtil.isEmptyWithTrim(ssbk)) {
			sql.append(" and ssbk = '"+ssbk+"' ");
		}
		String ssqy = whereMap.get("ssqy");
		if(!StringUtil.isEmptyWithTrim(ssqy)) {
			sql.append(" and ssqy = '"+ssqy+"' ");
		}
		String jszt = whereMap.get("jszt");
		if(!StringUtil.isEmptyWithTrim(jszt)) {
			sql.append(" and jszt = '"+jszt+"' ");
		}
		String djzt = whereMap.get("djzt");
		if(!StringUtil.isEmptyWithTrim(djzt)) {
			sql.append(" and djzt = '"+djzt+"' ");
		}
		String nccszxm = whereMap.get("nccszxm");
		if(!StringUtil.isEmptyWithTrim(nccszxm)) {
			sql.append(" and nccszxm = '"+nccszxm+"' ");
		}
		String nccjhxm = whereMap.get("nccjhxm");
		if(!StringUtil.isEmptyWithTrim(nccjhxm)) {
			sql.append(" and nccjhxm = '"+nccjhxm+"' ");
		}
		String nccxjllxm = whereMap.get("nccxjllxm");
		if(!StringUtil.isEmptyWithTrim(nccxjllxm)) {
			sql.append(" and nccxjllxm = '"+nccxjllxm+"' ");
		}
		
		String djrq_start = whereMap.get("djrq_start");
		if(!StringUtil.isEmptyWithTrim(djrq_start)) {
			sql.append(" and djrq >= '"+djrq_start+"' ");
		}
		String djrq_end = whereMap.get("djrq_end");
		if(!StringUtil.isEmptyWithTrim(djrq_end)) {
			sql.append(" and djrq <= '"+djrq_end+"' ");
		}
		
		String jsrq_start = whereMap.get("jsrq_start");
		if(!StringUtil.isEmptyWithTrim(jsrq_start)) {
			sql.append(" and jsrq >= '"+jsrq_start.split(",")[0]+"' ");
		}
		
		String jsrq_end = whereMap.get("jsrq_end");
		if(!StringUtil.isEmptyWithTrim(jsrq_end)) {
			sql.append(" and jsrq <= '"+jsrq_end.split(",")[0]+"' ");
		}
		
		String org_org_v_pk = whereMap.get("org_org_v_pk");
		if(!StringUtil.isEmptyWithTrim(org_org_v_pk)) {
			sql.append(" and gsmc = '"+org_org_v_pk+"' ");
		}
		
	}
	
	private static void setFieldByType(Field fd, JavaType type, int ilength) {
		if (type == JavaType.UFDouble || type == JavaType.BigDecimal) {
			fd.setDbColumnType(Types.DECIMAL);
			fd.setPrecision(28);
			fd.setScale(8);
		} else if (type == JavaType.UFBoolean) {
			fd.setDbColumnType(Types.CHAR);
			fd.setPrecision(1);
		} else if (type == JavaType.UFDate || type == JavaType.UFDateTime
				|| type == JavaType.UFTime) {
			fd.setDbColumnType(Types.VARCHAR);
			fd.setPrecision(19);
		} else if (type == JavaType.Integer || type == JavaType.UFFlag) {
			fd.setDbColumnType(Types.INTEGER);
		} else if (type == JavaType.UFStringEnum) {
			fd.setDbColumnType(Types.VARCHAR);
			fd.setPrecision(30);
		} else if (type == JavaType.String) {
			fd.setDbColumnType(Types.VARCHAR);
			if (ilength >= 0) {
				fd.setPrecision(ilength);
			} else {
				fd.setPrecision(100);
			}
		} else {
			ExceptionUtils
					.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl
							.getNCLangRes().getStrByID("4008019_0",
									"04008019-0049")/*
													 * @res "不支持的类型"
													 */);
		}
	}
	
}
