package nc.bs.arap.impl;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import nc.bs.arap.plugin.GetDataUtil;
import nc.bs.framework.adaptor.IHttpServletAdaptor;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.framework.server.ISecurityTokenCallback;
import nc.bs.servlet.service.BaseServlet;
import nc.itf.uap.pf.IPFBusiAction;
import nc.log.NcLog;
import nc.vo.arap.payable.AggPayableBillVO;
import nc.vo.arap.payable.PayableBillItemVO;
import nc.vo.arap.payable.PayableBillVO;
import nc.vo.org.FinanceOrgVO;
import nc.vo.pu.m25.entity.InvoiceItemVO;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pub.workflownote.WorkflownoteVO;

/**
 * 应付单
 * @author Yaoyu
 *
 */
public class PayableBillImpl extends BaseServlet implements IHttpServletAdaptor{

	@Override
	public void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String billno = "";
		try {
			NCLocator.getInstance().lookup(ISecurityTokenCallback.class).token("NCSystem".getBytes(),"pfxx".getBytes());
			String createStr = buildJson(req, resp, this.getClass().getName());
			JSONObject json = JSON.parseObject(createStr);
			NcLog.info("应付单:"+json.toString());
			billno = json.getString("billno");
			InvocationInfoProxy.getInstance().setUserDataSource("NC6337");
			GetDataUtil.getBillno(billno);
			checkJson(json);
			AggPayableBillVO aggPayableBillVO = new AggPayableBillVO ();
			PayableBillVO payableBillVO = new PayableBillVO();
			String userPK = GetDataUtil.getUserPK(json.getString("billmaker"));
			String pk_group = GetDataUtil.getGroupPK(json.getString("pk_group"));

			InvocationInfoProxy.getInstance().setUserId(userPK);//用户主键
			InvocationInfoProxy.getInstance().setGroupId(pk_group);//指定集团pk
			//集团
			payableBillVO.setPk_group(pk_group);
			String pk_tradetype = json.getString("pk_tradetype");
			//应付单类型编码
			payableBillVO.setPk_tradetype(pk_tradetype);
			String pk_billtypeid = GetDataUtil.getBilltypePK(pk_tradetype,pk_group);
			//应付类型
			payableBillVO.setPk_tradetypeid(pk_billtypeid);
			FinanceOrgVO financeOrgVO = GetDataUtil.getFinanceOrgVO(json.getString("pk_org"));
			//财务组织
			payableBillVO.setPk_fiorg(financeOrgVO.getPk_financeorg());
			//废弃财务组织版本 
			payableBillVO.setPk_fiorg_v(financeOrgVO.getPk_vid());
			//应付财务组织
			payableBillVO.setPk_org(financeOrgVO.getPk_financeorg());
			//应付财务组织版本
			payableBillVO.setPk_org_v(financeOrgVO.getPk_vid());
			//结算财务组织
			payableBillVO.setSett_org(financeOrgVO.getPk_financeorg());
			//结算财务组织版本
			payableBillVO.setSett_org_v(financeOrgVO.getPk_vid());
			//业务组织
			payableBillVO.setPu_org(financeOrgVO.getPk_financeorg());
			//业务组织版本
			payableBillVO.setPu_org_v(financeOrgVO.getPk_vid());
			//单据号
			payableBillVO.setBillno(json.getString("billno"));
			//单据日期
			payableBillVO.setBilldate(new UFDate(json.getString("billdate")));
			if("F1-0xx-01".equals(pk_tradetype)) {
				//起算日期
				payableBillVO.setBusidate(new UFDate(json.getString("busidate")));	
			}else {
				//起算日期
				payableBillVO.setBusidate(new UFDate(json.getString("billdate")));	
			}
						
			//制单人
			payableBillVO.setBillmaker(userPK);
			//创建人
			payableBillVO.setCreator(userPK);
			//创建时间
			payableBillVO.setCreationtime(new UFDateTime(json.getString("billdate")));
			String pk_dept = GetDataUtil.getDeptPK(json.getString("pk_deptid"));
			//费用使用部门
			payableBillVO.setPk_deptid(pk_dept);
			//业务部门
			payableBillVO.setPu_deptid(pk_dept);	
			String pk_vid = GetDataUtil.getDeptVPK(json.getString("pk_deptid_v"));
			if(pk_vid == null) {
				pk_vid = GetDataUtil.getDeptVPK(json.getString("pk_deptid"));
			}
			//部门版本信息
			payableBillVO.setPk_deptid_v(pk_vid);
			//业务部门版本
			payableBillVO.setPu_deptid_v(pk_vid);
					
			//对方单位名称
			payableBillVO.setSupplier(GetDataUtil.getSupplierPK(json.getString("supplier")));
			//组织本币金额
			payableBillVO.setLocal_money(new UFDouble(json.getString("local_money")));
			//原币金额
			payableBillVO.setMoney(new UFDouble(json.getString("local_money")));
			String recaccount = GetDataUtil.getBankaccsubPK(json.getString("recaccount"));
			//对方单位银行账户
			payableBillVO.setRecaccount(recaccount);
			//发票张数
			payableBillVO.setAccessorynum(Integer.parseInt(json.getString("accessorynum")));
			//业务流程
			payableBillVO.setPk_busitype(GetDataUtil.getBusitypePK(json.getString("pk_busitype")));
			//单据会计年度
			payableBillVO.setBillyear(json.getString("billyear"));
			//单据会计期间
			payableBillVO.setBillperiod(json.getString("billperiod"));
			String payaccount = GetDataUtil.getBankaccsubPK(json.getString("payaccount"));
			//付款银行账户
			payableBillVO.setPayaccount(payaccount);   
			String pk_currtype = GetDataUtil.getCurrtypePK(json.getString("pk_currtype"));
			//币种
			payableBillVO.setPk_currtype(pk_currtype);
			String pk_psndoc = GetDataUtil.getPsndocPK(json.getString("pk_psndoc"));
			//业务员
			payableBillVO.setPk_psndoc(pk_psndoc);
			//业务人员
			payableBillVO.setPu_psndoc(pk_psndoc);
			//单据来源系统 默认来源采购系统
			payableBillVO.setSrc_syscode(Integer.parseInt(json.getString("src_syscode")));	

			//是否打印备注
			payableBillVO.setDef1(GetDataUtil.getDefdocPK(json.getString("def1"), "19", "是否打印备注"));
			//建议付款日期
			payableBillVO.setDef3(json.getString("def3"));	
			//组长审批
			payableBillVO.setDef4(GetDataUtil.getPsndocPK(json.getString("def4")));
			//费用承担部门
			payableBillVO.setDef5(GetDataUtil.getDeptPK(json.getString("def5")));
			//分包类型
			payableBillVO.setDef10(GetDataUtil.getDefdocPK(json.getString("def10"), "13", "分包类型"));
			//员工编号
			payableBillVO.setDef13(json.getString("def13"));
			//来源单号
			payableBillVO.setDef15(json.getString("15"));
			//预算所在部门
			payableBillVO.setDef20(GetDataUtil.getDeptPK(json.getString("def20")));
			//应付单非项目——是否公司费用
			//预付核销非项目——待核销的预付单号
			//是否公司费用
			payableBillVO.setDef21(json.getString("def21"));
			//对方单位开户行
			payableBillVO.setDef25(json.getString("def25"));
			//是否一致
			payableBillVO.setDef33(json.getString("def33"));			
			//单据类型编码
			payableBillVO.setPk_billtype("F1");
			//单据大类
			payableBillVO.setBillclass("yf");
			//国家地区 默认CN
			String pk_country = GetDataUtil.getCountryzonePK("CN");
			payableBillVO.setRececountryid(pk_country);
			//报税国 默认CN
			payableBillVO.setTaxcountryid(pk_country);
			//单据所属系统 默认所属应付系统
			payableBillVO.setSyscode(1);			
			//结算方式 取表体第一行赋给表头
			payableBillVO.setPk_balatype(GetDataUtil.getBalatypePK(json.getJSONArray("childrenVO").getJSONObject(0).getString("pk_balatype")));
			//往来对象  取表体第一行赋给表头
			payableBillVO.setObjtype(Integer.parseInt(json.getJSONArray("childrenVO").getJSONObject(0).getString("pk_balatype")));
			payableBillVO.setBillstatus(-1);
			payableBillVO.setStatus(2);		
			//是否红冲过
			payableBillVO.setIsreded(UFBoolean.FALSE);
			//是否流程单据
			payableBillVO.setIsflowbill(UFBoolean.FALSE);
			aggPayableBillVO.setParentVO(payableBillVO);
			List<PayableBillItemVO> listPayableBillItemVO = new ArrayList<PayableBillItemVO>();
			JSONArray josns = json.getJSONArray("childrenVO");
			for (int i = 0; i < josns.size(); i++) {
				PayableBillItemVO payableBillItemVO = new PayableBillItemVO();
				JSONObject item = josns.getJSONObject(i);
				//预算编号
				payableBillItemVO.setDef1(item.getString("pk_subjcode"));
				//预算名称
				payableBillItemVO.setPk_subjcode(GetDataUtil.getInoutbusiclassPK(item.getString("pk_subjcode")));
				/**
				 * 应付单非项目——备注
					应付单项目——备注
					预付核销非项目——备注
					预付核销项目——备注

				 */
				//备注
				payableBillItemVO.setDef2(item.getString("def2"));
				//票据/保理申请编号
				payableBillItemVO.setDef5(item.getString("def5"));
				//专业
				payableBillItemVO.setDef6(GetDataUtil.getDefdocPK(item.getString("def6"), "HR016", "专业"));
				//费用事项
				payableBillItemVO.setDef7(GetDataUtil.getDefdocPK(item.getString("def7"), "88", "费用事项"));
				/**
				 * 内部应付单——备注
				 */
				//备注
				payableBillItemVO.setDef10(item.getString("def10"));
				//发票号
				payableBillItemVO.setDef12(item.getString("def12"));
				//应付单非项目def13参照的自定义档案
				//预付核销非项目def参照的客户基础档案
				
				if("F1-Cxx-04".equals(pk_tradetype)) {
					//客户
					payableBillItemVO.setDef13(GetDataUtil.getCustomerPK(item.getString("def13")));	
				}else {
					//客户
					payableBillItemVO.setDef13(GetDataUtil.getDefdocPK(item.getString("def13"), "CUST", "客户"));
				}
				
				//经营合同名称
				payableBillItemVO.setDef15(GetDataUtil.getDefdocPK(item.getString("def15"), "01", "分包合同"));
				//原发票日期
				payableBillItemVO.setDef17(item.getString("def17"));	
				//项目名称
				payableBillItemVO.setProject(GetDataUtil.getprojectPK(item.getString("project")));
				//项目编码
				payableBillItemVO.setDef18(item.getString("project"));
				//分包合同名称
				payableBillItemVO.setDef20(GetDataUtil.getDefdocPK(item.getString("def20"), "01", "分包合同"));
				//汇款附言
				payableBillItemVO.setDef21(item.getString("def21"));
				/**
				 * 应付单非项目——客户层级
				 * 应付单项目——成本归属部门
					预付核销非项目——客户层级
					预付核销项目——成本归属部门

				 */
				if("F1-Cxx-02".equals(pk_tradetype) || "F1-Cxx-05".equals(pk_tradetype) || "F1-Cxx-03".equals(pk_tradetype)) {
					//成本归属部门
					payableBillItemVO.setDef22(GetDataUtil.getDeptPK(item.getString("def22")));

				}else {
					//客户层级
					payableBillItemVO.setDef22(item.getString("def22"));
				}
				
				//应付单非项目使用的自定义23    成本归属部门
				payableBillItemVO.setDef23(GetDataUtil.getDeptPK(item.getString("def23")));
				//摘要
				payableBillItemVO.setDef25(GetDataUtil.getDefdocPK(item.getString("def25"), "999", "摘要"));
				/**
				 * 应付单非项目——民航发展基金
					应付单项目——民航发展基金
					预付核销非项目——民航发展基金
					预付核销项目——民航发展基金
					内部应付单——付款业务性质
				 */
				if("F1-0xx-01".equals(pk_tradetype)) {
					//付款业务性质
					payableBillItemVO.setDef29(GetDataUtil.getDefdocPK(item.getString("def29"), "YS001", "付款业务性质"));
				}else {
					//民航发展基金
					payableBillItemVO.setDef29(item.getString("def29"));
				}
				
				//费用归属
				payableBillItemVO.setDef30(GetDataUtil.getDefdocPK(item.getString("def30"), "05", "费用归属"));
				//人员
				payableBillItemVO.setDef40(GetDataUtil.getPsndocPK(item.getString("def40")));
				//发票查看
				payableBillItemVO.setDef41(item.getString("def41"));				
				//物料
				payableBillItemVO.setMaterial(GetDataUtil.getMaterialPK(item.getString("material")));
				//贷方数量
				payableBillItemVO.setQuantity_cr("".equals(item.getString("quantity_cr")) ? null : new UFDouble(item.getString("quantity_cr")));
				//数量余额
				payableBillItemVO.setQuantity_bal("".equals(item.getString("quantity_cr")) ? null : new UFDouble(item.getString("quantity_cr")));
				//结算方式
				payableBillItemVO.setPk_balatype(GetDataUtil.getBalatypePK(item.getString("pk_balatype")));
				//税码
				payableBillItemVO.setTaxcodeid(GetDataUtil.getTaxcodePK(item.getString("taxcodeid")));
				//税率
				payableBillItemVO.setTaxrate(new UFDouble(item.getString("taxrate")));
				//单价
				payableBillItemVO.setPrice("".equals(item.getString("price")) ? null : new UFDouble(item.getString("price")));
				//本币单价 
				payableBillItemVO.setLocal_price("".equals(item.getString("price")) ? null : new UFDouble(item.getString("price")));
				//含税单价
				payableBillItemVO.setTaxprice("".equals(item.getString("taxprice")) ? null : new UFDouble(item.getString("taxprice")));
				//本币含税单价
				payableBillItemVO.setLocal_taxprice("".equals(item.getString("taxprice")) ? null : new UFDouble(item.getString("taxprice")));
				//组织本币无税金额
				payableBillItemVO.setLocal_notax_cr(new UFDouble(item.getString("local_notax_cr")));
				//贷方原币无税金额
				payableBillItemVO.setNotax_cr(new UFDouble(item.getString("local_notax_cr")));
				//计税金额
				payableBillItemVO.setCaltaxmny(new UFDouble(item.getString("local_notax_cr")));
				//税额
				payableBillItemVO.setLocal_tax_cr(new UFDouble(item.getString("local_tax_cr")));
				//组织本币余额
				payableBillItemVO.setLocal_money_bal(new UFDouble(item.getString("local_money_cr")));
				//预占用原币余额
				payableBillItemVO.setOccupationmny(new UFDouble(item.getString("local_money_cr")));
				//原币余额
				payableBillItemVO.setMoney_bal(new UFDouble(item.getString("local_money_cr")));
				//贷方原币金额 
				payableBillItemVO.setMoney_cr(new UFDouble(item.getString("local_money_cr")));
				//组织本币金额
				payableBillItemVO.setLocal_money_cr(new UFDouble(item.getString("local_money_cr")));
				//往来对象
				payableBillItemVO.setObjtype(Integer.parseInt(item.getString("objtype")));
				//对方单位名称
				payableBillItemVO.setSupplier(GetDataUtil.getSupplierPK(item.getString("supplier")));
				//付款部门
				payableBillItemVO.setPk_deptid("".equals(item.getString("pk_deptid")) ? pk_dept : GetDataUtil.getDeptPK(item.getString("pk_deptid")));
				//部门版本
				payableBillItemVO.setPk_deptid_v(pk_vid);
				//行号
				payableBillItemVO.setRowno(Integer.parseInt(item.getString("rowno")));
				//发票号
				String invoiceno = item.getString("invoiceno");
				InvoiceItemVO invoiceItemVO = GetDataUtil.getInvoice(invoiceno, item.getString("invoicenorowno"));
				//上层单据主键
				payableBillItemVO.setTop_billid("".equals(invoiceno) ? null : invoiceItemVO.getPk_invoice());
				//上层单据类型
				payableBillItemVO.setTop_billtype(item.getString("top_billtype"));
				//上层单据行主键
				payableBillItemVO.setTop_itemid("".equals(invoiceno) ? null : invoiceItemVO.getPk_invoice_b());
				//上层交易类型 
				payableBillItemVO.setTop_tradetype(item.getString("top_tradetype"));
				//合同号
				payableBillItemVO.setContractno(item.getString("contractno"));
				//订单号
				payableBillItemVO.setPurchaseorder(item.getString("purchaseorder"));
				//源头单据号
				String vfirstcode = item.getString("vfirstcode");
				if(!"".equals(vfirstcode)) {
					//源头单据类型
					String  src_billtype = item.getString("src_billtype");
					//源头单据行号
					String vfirstrowno = item.getString("vfirstrowno");
					Map<String,String> map = GetDataUtil.getDataMap(src_billtype, vfirstcode, vfirstrowno);
					//源头单据主键
					payableBillItemVO.setSrc_billid(map.get("pk_id"));
					//源头单据行主键
					payableBillItemVO.setSrc_itemid(map.get("pk_id_b"));
					//源头单据类型
					payableBillItemVO.setSrc_billtype(src_billtype);
					//源头交易类型
					payableBillItemVO.setSrc_tradetype(GetDataUtil.getBilltypePK(item.getString("src_tradetype"), pk_group));
				}
				//购销类型
				payableBillItemVO.setBuysellflag(Integer.parseInt(item.getString("buysellflag")));
				//扣税类别
				payableBillItemVO.setTaxtype(Integer.parseInt(item.getString("taxtype")));
				//是否逆向征税
				payableBillItemVO.setOpptaxflag(UFBoolean.FALSE);
				//单据大类
				payableBillItemVO.setBillclass("yf");
				//单据日期
				payableBillItemVO.setBilldate(new UFDate(json.getString("billdate")));
				//单据号
				payableBillItemVO.setBillno(json.getString("billno"));
				if("F1-0xx-01".equals(pk_tradetype)) {
					//起算日期
					payableBillItemVO.setBusidate(new UFDate(json.getString("busidate")));	
				}else {
					//起算日期
					payableBillItemVO.setBusidate(new UFDate(json.getString("billdate")));	
				}
				//方向 默认贷方
				payableBillItemVO.setDirection(-1);
				payableBillItemVO.setInvoiceno(invoiceno);
				//不可抵扣税率
				payableBillItemVO.setNosubtaxrate(new UFDouble(0));
				//不可抵扣税额
				payableBillItemVO.setNosubtax(new UFDouble(0));
				//单据类型编码
				payableBillItemVO.setPk_billtype("F1");
				//币种
				payableBillItemVO.setPk_currtype(pk_currtype);
				//废弃财务组织
				payableBillItemVO.setPk_fiorg(financeOrgVO.getPk_financeorg());
				//废弃财务组织版本 
				payableBillItemVO.setPk_fiorg_v(financeOrgVO.getPk_vid());
				//所属集团
				payableBillItemVO.setPk_group(pk_group);
				//应付财务组织
				payableBillItemVO.setPk_org(financeOrgVO.getPk_financeorg());
				//结算财务组织
				payableBillItemVO.setSett_org(financeOrgVO.getPk_financeorg());
				//结算财务组织版本 
				payableBillItemVO.setSett_org_v(financeOrgVO.getPk_vid());
				//应付财务组织版本
				payableBillItemVO.setPk_org_v(financeOrgVO.getPk_vid());
				//应付类型code
				payableBillItemVO.setPk_tradetype(pk_tradetype);
				//应付类型
				payableBillItemVO.setPk_tradetypeid(pk_billtypeid);
				//rate组织本币汇率 
				payableBillItemVO.setRate(new UFDouble(1));
				//收款银行账户
				payableBillItemVO.setRecaccount(recaccount);
				//付款银行账户
				payableBillItemVO.setPayaccount(payaccount);
				//行类型
				payableBillItemVO.setRowtype(0);
				//发货国
				payableBillItemVO.setSendcountryid(pk_country);
				//业务员
				payableBillItemVO.setPk_psndoc(pk_psndoc);
				//业务人员
				payableBillItemVO.setPu_psndoc(pk_psndoc);
				//业务部门
				payableBillItemVO.setPu_deptid(pk_dept);
				//业务部门版本
				payableBillItemVO.setPu_deptid_v(pk_vid);
				//业务组织
				payableBillItemVO.setPu_org(financeOrgVO.getPk_financeorg());
				//业务组织版本
				payableBillItemVO.setPu_org_v(financeOrgVO.getPk_vid());
				payableBillItemVO.setStatus(2);
				listPayableBillItemVO.add(payableBillItemVO);
			}
			aggPayableBillVO.setChildrenVO(listPayableBillItemVO.toArray(new PayableBillItemVO[listPayableBillItemVO.size()]));
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Object dateTimeString  = payableBillVO.getBilldate();
			if(dateTimeString != null) {
			    Date date = format.parse(dateTimeString.toString());
			    long timestamp = date.getTime();
			    InvocationInfoProxy.getInstance().setBizDateTime(timestamp);
			 }
			
			
			WorkflownoteVO Workflownote = new WorkflownoteVO();
			IPFBusiAction ipf = NCLocator.getInstance().lookup(IPFBusiAction.class);
			ipf.processAction("SAVE", "F1", Workflownote, aggPayableBillVO, null, null);
			resp.getWriter().write(formatRSJsonData("成功", "", billno).toString());
		} catch (Exception e) {
			resp.getWriter().write(formatRSJsonData("失败",e.getMessage() == null ? "" : e.getMessage(),billno).toString());
			StringWriter stringWriter = new StringWriter();
			e.printStackTrace(new PrintWriter(stringWriter));
			//获取详细信息
			String msg=stringWriter.getBuffer().toString();
			NcLog.info("应付单:"+msg);
		}
	}
		
	private void checkJson(JSONObject json) throws Exception {
		
		StringBuffer mags = new StringBuffer();
		Boolean empty = true;
		
		String pk_group = "pk_group";
		String pk_tradetype = "pk_tradetype";
		String pk_org = "pk_org";
		String billno = "billno";
		String billdate = "billdate";
		String billmaker = "billmaker";
		String local_money = "local_money";
		String accessorynum = "accessorynum";
		String pk_busitype = "pk_busitype";
		String billyear = "billyear";
		String billperiod = "billperiod";
		String pk_currtype = "pk_currtype";
		String src_syscode = "src_syscode";
	
		String body = "childrenVO";//表体
		String[] HeadKey = {pk_group,pk_tradetype,pk_org,billno,billdate,billmaker,local_money,accessorynum,
				pk_busitype,billyear,billperiod,pk_currtype,src_syscode};
		
		for (String as : HeadKey) {

			if (json.getString(as).isEmpty()) {
				empty = false;
				mags.append("'" + as + "'");
			}
		}
		if (json.getJSONArray(body)==null) {
			empty = false;
			mags.append("表体不存在！ ");
		}
		
		JSONArray childrenVO = json.getJSONArray("childrenVO");
		
		if (childrenVO == null || childrenVO.size() == 0) {
			throw new Exception("表体内容不可为空！");
		}
		
		String taxcodeid = "taxcodeid";
		String taxrate = "taxrate";
		String local_notax_cr = "local_notax_cr";
		String local_tax_cr = "local_tax_cr";
		String local_money_cr = "local_money_cr";
		String objtype = "objtype";
		String rowno = "rowno";
		String buysellflag = "buysellflag";
		String taxtype = "taxtype";
		for(int i = 0; i < childrenVO.size(); i++) {
			
			JSONObject oprepJsonObjectB = childrenVO.getJSONObject(i);
			String[] BodyKey = {taxcodeid,taxrate,local_notax_cr,local_tax_cr,local_money_cr,
					objtype,rowno,buysellflag,taxtype};
			int num = i+1;
			
			mags.append("第"+num+"块表体：{");
			for (String as : BodyKey) {
				if (oprepJsonObjectB.getString(as).isEmpty()) {
					empty = false;
					mags.append("'" + as + "' ");
				}
			}
			mags.append("}");
		}
		if (!empty) {
			throw new Exception("以下字段不可为空："+mags);
		}
	}
}
