package weaver.fna.invoice.utils;

import com.engine.fna.util.FnaInvoiceUploadUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import weaver.conn.RecordSet;
import weaver.fna.general.FnaLogSqlUtil;
import weaver.fna.invoice.Constants;
import weaver.fna.invoice.common.FnaAbstractInterface;
import weaver.fna.invoice.common.FnaInvoiceCommon;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: lb2018
 * @Description:
 * @Date: 2020/9/8 18:24
 */
public class InvoiceRecognitionUtil {

	/**发票不存在*/
	private static final String INVOICE_NOT_EXISTS = "0";
	/**增值税普通*/
	private static final String VAT_ORDINARY_TYPE = "1";
	/**增值税专用*/
	private static final String VAT_SPECIAL_TYPE = "2";
	/**通用机打发票*/
	private static final String GENERALMACHINE_TYPE = "3";
	/**定额发票*/
	private static final String QUOTA_TYPE = "5";
	/**出租发票*/
	private static final String TAXI_TYPE = "7";
	/**动车高铁票*/
	private static final String TRAIN_TYPE = "8";
	/**过路费发票*/
	private static final String TOLLS_TYPE = "9";
	/**客运汽车票*/
	private static final String PASSENGERTICKET_TYPE = "10";
	/**二手车销售统一发票*/
	private static final String USEDCARSALES_TYPE = "11";
	/**机动车销售统一发票*/
	private static final String MOTORVEHICLESALES_TYPE = "12";
	/**航空运输电子客票行程单*/
	private static final String AIRTRANSPORTTICKET_TYPE = "14";
	/**增值税电子普通发票*/
	private static final String VAT_Electronic_Type = "15";
	/**增值税普通发票（卷票）*/
	private static final String VAT_ORDINARY_Volume_TYPE = "16";
	/**可报销其他发票*/
	private static final String OTHERS_TYPE = "17";
	/**完税证明*/
	private static final String TAX_CERTIFICATE_TYPE = "18";
	/**区块链*/
	private static final String BLOCKCHAIN_TYPE = "19";
	/**增值税电子普通发票(通行费)*/
	private static final String VAT_Electronic_Tolls_Type = "20";
	/**增值税电子专用发票*/
	private static final String VAT_Electronic_SPECIAL_Type = "21";
	/**全电票（电子专票）*/
	private static final String VAT_ELEC_TYPE = "32";
	/**全电票（普通发票）*/
	private static final String VAT_GENE_TYPE = "33";

	private static FnaLogSqlUtil fnaLogSqlUtil = new FnaLogSqlUtil();

	public static Map<String, Object> handler(String fptpId, String ipAdress, User user){
		Map<String, Object> result = new HashMap<String, Object>();
		try{

			BaseBean bb = new BaseBean();
			RecordSet rs = new RecordSet();
			String imagefilename = FnaInvoiceUploadUtil.getImagefilename(fptpId);
			String invoiceIds = "";
			String suffix = FnaInvoiceUploadUtil.getFileSuffix(fptpId);
			if("jpg".equalsIgnoreCase(suffix)||"jpeg".equalsIgnoreCase(suffix)||"gif".equalsIgnoreCase(suffix)
					||"png".equalsIgnoreCase(suffix)||"pdf".equalsIgnoreCase(suffix) ||"ofd".equalsIgnoreCase(suffix)){
				String fileData = FnaInvoiceUploadUtil.changeFileTobase64(Integer.parseInt(fptpId));
				if("".equals(fileData)){
					throw new Exception(imagefilename+"获取发票信息失败！");
				}

				byte[] imageBytes = ImageUtil.transformImage(fileData);
				JSONObject returnJson = HttpUtil.postImage(imageBytes,user);
				int status = returnJson.getInt("status");
				if (status == Constants.ERROR_CODE) {
					throw new Exception(imagefilename+returnJson.getString("errMsg"));
				}
				String errorMsg = FnaInvoiceUploadUtil.getIdentifyMsg(returnJson, user);
				if(!"".equals(errorMsg)){//识别结果错误
					FnaInvoiceCommon.saveFailLog(user.getUID(), 0, errorMsg);
					throw new Exception(imagefilename+errorMsg);
				}
				int userid = user.getUID();
				String entryTime = Util.date(2);//录入时间
				JSONArray identify_results_array = JSONObject.fromObject(returnJson.get("returnInfo")).getJSONObject("response").getJSONObject("data")
						.getJSONArray("identify_results");
				int identifyArraySize = identify_results_array.size();
				int imageID = 0;
				if(identifyArraySize == 1 || "pdf".equalsIgnoreCase(suffix) || "ofd".equalsIgnoreCase(suffix)){
					imageID = Integer.parseInt(fptpId);
				}
				DecimalFormat df = new DecimalFormat("##########################0.00");
				FnaInvoiceCommon fnaInvoiceCommon = new FnaInvoiceCommon();
				StringBuffer uploadMsg = new StringBuffer();
				boolean existsInterface = InvoiceUtil.ifExistsInterface(user);
				new BaseBean().writeLog("identifyArraySize", identifyArraySize);
				for (int i = 0; i < identifyArraySize; i++) {
					JSONObject identify_results = identify_results_array.getJSONObject(i);
					String orientation = identify_results.getString("orientation");
					bb.writeLog("identify_results:" + identify_results);
					if(identifyArraySize > 1 && !"pdf".equalsIgnoreCase(suffix) && !"ofd".equalsIgnoreCase(suffix)){
						String region = identify_results.getString("region");
						String[] regions = region.replace("[", "").replace("]", "").split(",");
						int x = 0;
						int w = 0;
						int h = 0;
						int y = 0;
						if(regions.length == 4){
							x = Util.getIntValue(regions[0]);
							y = Util.getIntValue(regions[1]);
							w = Util.getIntValue(regions[2]);
							h = Util.getIntValue(regions[3]);
							if(x==0){
								x++;
							}
							if(y==0){
								y++;
							}
							String cutImageBase64 = ImageUtil.cutImg(x,y,w-x,h-y,imageBytes,orientation);
							imageID = ImageUtil.saveImage(cutImageBase64,user);
						}
					}
					bb.writeLog("解析发票开始:" + i + "################################################");
					String type = identify_results.getString("type");
					JSONObject details = identify_results.getJSONObject("details");



					//通过title和block_chain 区分可报销其他发票和区域链发票
					if("10100".equals(type) || "10101".equals(type) || "10102".equals(type) || "10103".equals(type)){
						String block_chain = getString(details,"block_chain");
						String transit_mark = getString(details,"transit_mark");//通行费标识
						String electronic_mark = getString(details,"electronic_mark");//电子专票标识
						if("1".equals(block_chain)){
							type="19";
						}
						if("1".equals(transit_mark)){
							type="20";
						}
						if("10100".equals(type) && "1".equals(electronic_mark)){
							type="21";
						}
					}


					if(details.containsKey("title")){
						String title = details.getString("title");
						if(!"".equals(title)) {
							if ("10100".equals(type) || "10101".equals(type) || "10102".equals(type) || "10103".equals(type)) {
								if (!title.contains("增值税")) {
									type = "10900";
								}
							} else if ("10104".equals(type)) {
								if (!title.contains("机动车")) {
									type = "10900";
								}
							}
						}
					}







					 if( "102015".equals(type)||"102021".equals(type)) {
						type = "10900";
						details.put("number", getString(details, "bill_number"));
						details.put("code", getString(details, "bill_code"));
						}



					boolean insertLog=false;
					int invoiceId=0;

					if ("10100".equals(type) || "21".equals(type)) {// 增值税专用发票
						String number = details.getString("number");
						String code = details.getString("code");
						if(!"".equals(number)&&!"".equals(code)){
							if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
								String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
										.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
								uploadMsg.append(msg);
								uploadMsg.append("\n");
								invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
							}
						}
						String invoiceType="";
						if("10100".equals(type)){
							invoiceType = VAT_SPECIAL_TYPE;
						}else if("21".equals(type)){
							invoiceType = VAT_Electronic_SPECIAL_Type;
						}

						double totalAmount =Util.getDoubleValue(MultiInvoiceUtil.getString(details, "total"),0.00);
						boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
						if(existsInterface && needCheck){
							invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
							String authenticityMsg = authenticityCheck(invoiceId, user,ipAdress);
							if(!"".equals(authenticityMsg)){
								uploadMsg.append(SystemEnv.getHtmlLabelName(384828,user.getLanguage()).replace("invoiceNumber", number)+authenticityMsg);
								uploadMsg.append("\n");
							}
						}else{
							invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					}  else if ("10107".equals(type)) {// 新型专票（电票）//32专用33普通
						String number = details.getString("number");
						//String code = details.getString("code");
						String code=number;
						if(!"".equals(number)){
							if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
								String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
										.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
								uploadMsg.append(msg);
								uploadMsg.append("\n");
								invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
							}
						}
						double totalAmount =Util.getDoubleValue(MultiInvoiceUtil.getString(details, "total"),0.00);
						boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
						if(existsInterface && needCheck){
							invoiceId = InvoiceUtil.saveVATInvoice(details,user,VAT_ELEC_TYPE,imageID,existsInterface,needCheck,ipAdress);
							String authenticityMsg = authenticityCheck(invoiceId, user,ipAdress);
							if(!"".equals(authenticityMsg)){
								uploadMsg.append(SystemEnv.getHtmlLabelName(384828,user.getLanguage()).replace("invoiceNumber", number)+authenticityMsg);
								uploadMsg.append("\n");
							}
						}else{
							invoiceId = InvoiceUtil.saveVATInvoice(details,user,VAT_ELEC_TYPE,imageID,existsInterface,needCheck,ipAdress);
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					}else if ("10108".equals(type)) {// 新型专票（电票）//32专用33普通
						String number = details.getString("number");
						//String code = details.getString("code");
						String code=number;
						if(!"".equals(number)){
							if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
								String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
										.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
								uploadMsg.append(msg);
								uploadMsg.append("\n");
								invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
							}
						}
						double totalAmount =Util.getDoubleValue(MultiInvoiceUtil.getString(details, "total"),0.00);
						boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
						if(existsInterface && needCheck){
							invoiceId = InvoiceUtil.saveVATInvoice(details,user,VAT_GENE_TYPE,imageID,existsInterface,needCheck,ipAdress);
							String authenticityMsg = authenticityCheck(invoiceId, user,ipAdress);
							if(!"".equals(authenticityMsg)){
								uploadMsg.append(SystemEnv.getHtmlLabelName(384828,user.getLanguage()).replace("invoiceNumber", number)+authenticityMsg);
								uploadMsg.append("\n");
							}
						}else{
							invoiceId = InvoiceUtil.saveVATInvoice(details,user,VAT_GENE_TYPE,imageID,existsInterface,needCheck,ipAdress);
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					} else if ("10101".equals(type) || "10102".equals(type) || "10103".equals(type) || "20".equals(type)) {// 增值税普通发票
						String number = details.getString("number");
						String code = details.getString("code");
						if(!"".equals(number)&&!"".equals(code)){
							if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
								String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
										.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
								uploadMsg.append(msg);
								uploadMsg.append("\n");
								invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
							}
						}
						String invoiceType="";
						if("10101".equals(type)){
							invoiceType = VAT_ORDINARY_TYPE;
						}else if("10102".equals(type)){
							invoiceType = VAT_Electronic_Type;
						}else if("10103".equals(type)){
							invoiceType = VAT_ORDINARY_Volume_TYPE;
						}else if("20".equals(type)){
							invoiceType = VAT_Electronic_Tolls_Type;
						}

						double totalAmount =Util.getDoubleValue(MultiInvoiceUtil.getString(details, "total"),0.00);
						boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
						if(existsInterface && needCheck){
							invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
							String authenticityMsg = authenticityCheck(invoiceId, user,ipAdress);
							if(!"".equals(authenticityMsg)){
								uploadMsg.append(SystemEnv.getHtmlLabelName(384828,user.getLanguage()).replace("invoiceNumber", number)+authenticityMsg);
								uploadMsg.append("\n");
							}
						}else{
							invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					} else if ("10104".equals(type)) {// 机动车销售统一发票
						String number = details.getString("number");
						String code = details.getString("code");
						if(!"".equals(number)&&!"".equals(code)){
							if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
								String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
										.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
								uploadMsg.append(msg);
								uploadMsg.append("\n");
							}
						}
						double totalAmount =Util.getDoubleValue(getString(details, "total"),0.00);
						boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);

						bb.writeLog("机动车销售统一发票", details);
						if("".equals(number)&&"".equals(code)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
							code = number;
						}else if(!"".equals(number)&&"".equals(code)){
							code = number;
						}else if("".equals(number)&&!"".equals(code)){
							number = code;
						}
						String date = MultiInvoiceUtil.getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

						String seller = getString(details, "seller");
						String buyer = getString(details, "buyer");
						String total = getString(details, "total");
						String machine_code = getString(details, "machine_code");// 机打代码
						String machine_number = getString(details, "machine_number");// 机打号码
						String pretax_amount = getString(details, "pretax_amount");// 税前金额
						String seller_tax_id = getString(details, "seller_tax_id");// 销售方纳税人识别号
						String buyer_id = getString(details, "buyer_id");// 买方单位代码/个人身份证号
						String tax_authorities = getString(details, "tax_authorities");// 主管税务机关
						String tax_authorities_code = getString(details, "tax_authorities_code");// 主管税务机关代码
						String car_code = getString(details, "car_code");// 买方单位代码/个人身份证号
						String car_engine_code = getString(details, "car_engine_code");// 发动机号码
						String car_model = getString(details, "car_model");// 厂牌型号
						String certificate_number = getString(details, "certificate_number");// 合格证号
						String tax= getString(details, "tax");
						String taxRate = getString(details, "tax_rate").replace("%","");

						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						if (invoiceId == 0) {
							String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,seller,purchaser,salesTaxNo,purchaserTaxNo,taxIncludedPrice,priceWithoutTax,tax,taxRate,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, date, code, number, MOTORVEHICLESALES_TYPE, seller, buyer,seller_tax_id,buyer_id, df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(pretax_amount, 0.00)),df.format(Util.getDoubleValue(tax, 0.00)),df.format(Util.getDoubleValue(taxRate, 0.00)), userid, "1","2",
									FnaInvoiceCommon.INIT_STATUS, imageID, FnaInvoiceCommon.INVOICESOURCE_OCR, entryTime);
							// 获取发票id
							invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
							String insertMotor_Vehicle = "insert into motor_VehicleInvoice(mainid,machine_code,machine_number,pretax_amount,seller_tax_id,buyer_id,tax_authorities,tax_authorities_code,car_code,"
									+ "car_engine_code,car_model,certificate_number) values(?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertMotor_Vehicle, invoiceId, machine_code, machine_number, pretax_amount,
									seller_tax_id, buyer_id, tax_authorities, tax_authorities_code, car_code, car_engine_code,
									car_model, certificate_number);
							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pretax_amount, 0.00)), df.format(Util.getDoubleValue(taxRate,0.00)),df.format(Util.getDoubleValue(tax,0.00)),1,df.format(Util.getDoubleValue(pretax_amount, 0.00)),df.format(Util.getDoubleValue(pretax_amount, 0.00)),"","");
							insertLog=true;
						}


						if(existsInterface && needCheck){
							String authenticityMsg = authenticityCheck(invoiceId, user,ipAdress);
							if(!"".equals(authenticityMsg)){
								uploadMsg.append(SystemEnv.getHtmlLabelName(384828,user.getLanguage()).replace("invoiceNumber", number)+authenticityMsg);
								uploadMsg.append("\n");
							}
						}

						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					} else if ("10105".equals(type)) {// 二手车销售统一发票
						bb.writeLog("二手车销售统一发票", details);
						String number = Util.null2String(getString(details, "number"));
						String code = getString(details, "code");
						if("".equals(number)&&"".equals(code)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
							code = number;
						}else if(!"".equals(number)&&"".equals(code)){
							code = number;
						}else if("".equals(number)&&!"".equals(code)){
							number = code;
						}

						if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
						}
						String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

						String total = getString(details, "total");
						String seller = getString(details, "seller");
						String buyer = getString(details, "buyer");
						String seller_id = getString(details, "seller_id");// 卖方单位代码/个人身份证号
						String buyer_id = getString(details, "buyer_id");// 买方单位代码/个人身份证号
						String company_name = getString(details, "company_name");// 二手车市场
						String company_tax_id = getString(details, "company_tax_id");// 二手车市场纳税人识别号
						String license_plate = getString(details, "license_plate");// 车牌号
						String registration_number = getString(details, "registration_number");// 登记证号
						String car_code = getString(details, "car_code");// 二手车市场
						String car_model = getString(details, "car_model");// 厂牌型号

						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						if (invoiceId == 0) {
							String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,seller,purchaser,taxIncludedPrice,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, date, code, number, USEDCARSALES_TYPE, seller, buyer, df.format(Util.getDoubleValue(total,0.00)), userid, "1","2",
									FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
							// 获取发票id
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
							// 插入二手车销售统一发票明细表
							String insertSecond_car = "insert into second_carInvoice(mainid,seller_id,buyer_id,company_name,company_tax_id"
									+ ",license_plate,registration_number,car_code,car_model) values(?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertSecond_car, invoiceId, seller_id, buyer_id, company_name, company_tax_id,
									license_plate, registration_number, car_code, car_model);

							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
							insertLog=true;
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					} else if ("10200".equals(type)) {// 定额发票
						bb.writeLog("定额发票", details);
						String number = Util.null2String(getString(details, "number"));
						String code = getString(details, "code");
						if("".equals(number)&&"".equals(code)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
							code = number;
						}else if(!"".equals(number)&&"".equals(code)){
							code = number;
						}else if("".equals(number)&&!"".equals(code)){
							number = code;
						}
						if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
						}
						String total = getString(details, "total");
						if ("".equals(total)) {
							total = "0.00";
						}
						String billingDate = "";

						//ocr增加字段

						String kind =getString(details, "kind");
						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						if (invoiceId == 0) {
							String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,taxIncludedPrice,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, billingDate, code, number, QUOTA_TYPE, df.format(Util.getDoubleValue(total,0.00)), userid, "1","2",
									FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind);
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);

							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
							insertLog=true;
						}

						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					} else if ("10400".equals(type)) {// 机打发票
						bb.writeLog("机打发票", details);
						String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

						String number = Util.null2String(getString(details, "number"));
						String code = getString(details, "code");
						if("".equals(number)&&"".equals(code)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
							code = number;
						}else if(!"".equals(number)&&"".equals(code)){
							code = number;
						}else if("".equals(number)&&!"".equals(code)){
							number = code;
						}

						if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
						}
						String seller = getString(details, "seller");
						String buyer = getString(details, "buyer");
						String total = getString(details, "total");
						String check_code = getString(details, "check_code");
						if ("".equals(total)) {
							total = "0.00";
						}
						String time = getString(details, "time");// 时间
						String category = getString(details, "category");// 种类，oil//
						String seller_tax_id = getString(details, "seller_tax_id");// 销售方纳税人识别号
						String buyer_tax_id = getString(details, "buyer_tax_id");// 购买方纳税人识别号
						String seller_addr_tel = MultiInvoiceUtil.getString(details, "seller_addr_tel");
						String seller_bank_account = MultiInvoiceUtil.getString(details, "seller_bank_account");
						String buyer_addr_tel = MultiInvoiceUtil.getString(details, "buyer_addr_tel");
						String buyer_bank_account = MultiInvoiceUtil.getString(details, "buyer_bank_account");
						//ocr增加字段
						String kind =getString(details, "kind");//发票消费类型
						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						if (invoiceId == 0) {
							String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,seller,purchaser,taxIncludedPrice,userid_new,checkcode,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,category,salesTaxNo,purchaserTaxNo,kind) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, date, code, number, GENERALMACHINE_TYPE, seller, buyer, df.format(Util.getDoubleValue(total,0.00)), userid, check_code,
									"1","2", FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,category,seller_tax_id,buyer_tax_id,kind);
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
							// 插入机打发票明细表
							String insertMachine = "insert into machineInvoice(mainid,time,category,seller_tax_id,buyer_tax_id) values(?,?,?,?,?)";
							rs.executeUpdate(insertMachine, invoiceId, time, category, seller_tax_id, buyer_tax_id);

							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
							InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0, invoiceId, "","", seller_addr_tel, buyer_addr_tel, seller_bank_account, buyer_bank_account);
							insertLog=true;
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;

					} else if ("10500".equals(type)) {// 出租车发票
						bb.writeLog("出租车发票", details);
						String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

						String code = getString(details, "code");
						String number = Util.null2String(getString(details, "number"));
						if("".equals(number)&&"".equals(code)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
							code = number;
						}else if(!"".equals(number)&&"".equals(code)){
							code = number;
						}else if("".equals(number)&&!"".equals(code)){
							number = code;
						}

						if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
						}

						String fare = getString(details, "fare");//原始金额
						String total = getString(details, "total");
						if (!"".equals(fare)) {
							total = fare;
						}
						if ("".equals(total)) {
							total = "0.00";
						}

						String time_geton = getString(details, "time_geton");// 上车时间
						String time_getoff = getString(details, "time_getoff");// 下车时间
						String mileage = getString(details, "mileage");// 里程
						//ocr增加字段
						String place =  getString(details, "place");// 发票所在地
						String kind =  getString(details, "kind");// 发票消费类型
						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						if (invoiceId == 0) {
							String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,taxIncludedPrice,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, date, code, number, TAXI_TYPE, df.format(Util.getDoubleValue(total,0.00)), userid, "1","2",
									FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind);
							// 获取发票id
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
							// 插入出租车发票明细表
							String insertTaxi = "insert into taxiInvoice(mainid,time_geton,time_getoff,mileage,place) values(?,?,?,?,?)";
							rs.executeUpdate(insertTaxi, invoiceId, time_geton, time_getoff, mileage,place);

							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
							insertLog=true;
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					} else if ("10503".equals(type)) {// 火车票
						bb.writeLog("火车票", details);
						String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

						String number = Util.null2String(getString(details, "serial_number"));
						if("".equals(number)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
						}

						if(fnaInvoiceCommon.ifExistAuthenticity(number, number, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,number)[3]);
						}
						String total = getString(details, "total");
						if ("".equals(total)) {
							total = "0.00";
						}
						//铁路旅客运输进项税额=票面金额÷（1+9%）×9%
						String taxRate="9";
						String tax = df.format(Util.getDoubleValue(total,0.00) / (1+0.09) * 0.09);
						String time = getString(details, "time");// 时间
						String name = getString(details, "name");// 乘车人姓名
						//未取得注明旅客身份信息
						if("".equals(name)){
							tax = "0.00";
							taxRate="0";
						}
						String pricewithouttax = df.format(Util.getDoubleValue(total)-Util.getDoubleValue(tax));
						String station_geton = getString(details, "station_geton");// 上车车站
						String station_getoff = getString(details, "station_getoff");// 下车车站
						String train_number = getString(details, "train_number");// 车次
						String seat = getString(details, "seat");// 座位类型
						//ocr增加字段
						String kind =  getString(details, "kind");// 发票消费类型
						invoiceId = Integer.parseInt(getInvoiceData(number,number)[3]);
						if (invoiceId == 0) {
							String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceNumber,invoiceCode,invoiceType,taxIncludedPrice,pricewithouttax,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind,taxRate,tax) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, date, number, number, TRAIN_TYPE, df.format(Util.getDoubleValue(total,0.00)),pricewithouttax, userid, "1","2",
									FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind,taxRate,tax);
							// 获取发票id
							invoiceId = Integer.parseInt(getInvoiceData(number,number)[3]);
							// 插入火车发票明细表
							String insertTrain = "insert into trainInvoice(mainid,time,name,station_geton,station_getoff,train_number,seat) values(?,?,?,?,?,?,?)";
							rs.executeUpdate(insertTrain, invoiceId, time, name, station_geton, station_getoff, train_number,
									seat);

							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");
							insertLog=true;
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					} else if ("10505".equals(type)) {// 客运汽车
						bb.writeLog("客运汽车", details);
						String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

						String code = getString(details, "code");
						String number = Util.null2String(getString(details, "number"));
						if("".equals(number)&&"".equals(code)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
							code = number;
						}else if(!"".equals(number)&&"".equals(code)){
							code = number;
						}else if("".equals(number)&&!"".equals(code)){
							number = code;
						}

						if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
						}
						String total = getString(details, "total");
						String time = getString(details, "time");// 时间
						String station_geton = getString(details, "station_geton");// 上车车站
						String station_getoff = getString(details, "station_getoff");// 下车车站
						String name = getString(details, "name");// 乘车人姓名
						if ("".equals(total)) {
							total = "0.00";
						}
						//公路、水路等其他旅客运输进项税额=票面金额÷（1+3%）×3%
						String taxRate="3";
						String tax = df.format(Util.getDoubleValue(total,0.00) / (1+0.03) * 0.03);
						//未取得注明旅客身份信息
						if("".equals(name)){
							tax = "0.00";
							taxRate="0";
						}
						String pricewithouttax = df.format(Util.getDoubleValue(total)-Util.getDoubleValue(tax));
						//ocr增加字段
						String kind =  getString(details, "kind");// 发票消费类型
						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						if (invoiceId == 0) {
							String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,taxIncludedPrice,pricewithouttax,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind,tax,taxRate) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, date, code, number, PASSENGERTICKET_TYPE, df.format(Util.getDoubleValue(total,0.00)),pricewithouttax, userid, "1","2",
									FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind,tax,taxRate);
							// 获取发票id
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
							// 插入客运汽车发票明细表
							String insertCar = "insert into carInvoice(mainid,time,station_geton,station_getoff,name) values(?,?,?,?,?)";
							rs.executeUpdate(insertCar, invoiceId, time, station_geton, station_getoff, name);

							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");
							insertLog=true;
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					} else if ("10506".equals(type)) {// 航空运输电子客票行程单
						bb.writeLog("航空运输电子客票行程单", details);
						String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

						String number = Util.null2String(getString(details, "number"));
						if("".equals(number)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
						}

						if(fnaInvoiceCommon.ifExistAuthenticity(number, number, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,number)[3]);
						}
						String total = getString(details, "total");
						String user_name = getString(details, "user_name");// 乘机人姓名
						String user_id = getString(details, "user_id");// 身份证号
						String agentcode = getString(details, "agentcode");// 销售单位代号
						String issue_by = getString(details, "issue_by");// 填开单位
						if ("".equals(total)) {
							total = "0.00";
						}
						String fare = getString(details, "fare");// 票价
						String fuel_surcharge = getString(details, "fuel_surcharge");// 燃油附加费
						//航空旅客运输进项税额=（票价+燃油附加费）÷（1+9%）×9%
						String taxRate="9";
						String tax = df.format((Util.getDoubleValue(fare,0.00)+Util.getDoubleValue(fuel_surcharge,0.00)) / (1+0.09) * 0.09);
						//未取得注明旅客身份信息
						if("".equals(user_name)){
							tax = "0.00";
							taxRate="0";
						}
						String pricewithouttax = df.format(Util.getDoubleValue(total)-Util.getDoubleValue(tax));
						String caac_development_fund = getString(details, "caac_development_fund");// 民航发展基金
						String insurance = getString(details, "insurance");// 保险费
						String check_code = getString(details, "check_code");// 验证码
						//ocr增加字段
						String kind =  getString(details, "kind");// 发票消费类型
						invoiceId = Integer.parseInt(getInvoiceData(number, number)[3]);
						if (invoiceId == 0) {
							String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceNumber,invoiceCode,invoiceType,tax,taxRate,taxIncludedPrice,pricewithouttax,userid_new,checkcode,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, date, number,number, AIRTRANSPORTTICKET_TYPE, tax, taxRate, df.format(Util.getDoubleValue(total,0.00)),pricewithouttax, userid, check_code, "1","2",
									FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind);
							// 获取发票id
							invoiceId = Integer.parseInt(getInvoiceData(number,number)[3]);
							// 插入飞机发票明细表
							String insertAir = "insert into airInvoice(mainid,user_name,user_id,agentcode,issue_by,fare,fuel_surcharge,caac_development_fund,insurance) values(?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertAir, invoiceId, user_name, user_id, agentcode, issue_by, fare,
									fuel_surcharge, caac_development_fund, insurance);
							JSONArray flights = details.getJSONArray("flights");
							for (int j = 0; j < flights.size(); j++) {
								JSONObject flightsjson = flights.getJSONObject(j);
								String from = getString(flightsjson, "from");// 出发站
								String to = getString(flightsjson, "to");// 到达站
								String flight_number = getString(flightsjson, "flight_number");// 航班号
								String flight_date = getString(flightsjson, "date").replace("年", "-").replace("月", "-")
										.replace("日", "");// 乘机日期

								String time = getString(flightsjson, "time");// 乘机时间
								String seat = getString(flightsjson, "seat");// 座位等级
								String carrier = getString(flightsjson, "carrier");// 承运人
								String insertAirDtl = "insert into airDtlInvoice(mainid,from_city,to_city,flight_number,airdate,airtime,seat,carrier) values(?,?,?,?,?,?,?,?)";
								rs.executeUpdate(insertAirDtl, invoiceId, from, to, flight_number, flight_date, time, seat,carrier);
							}

							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");
							insertLog=true;
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					} else if ("10507".equals(type)) {// 过路费发票
						bb.writeLog("过路费发票", details);
						String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

						String code = getString(details, "code");
						String number = Util.null2String(getString(details, "number"));
						if("".equals(number)&&"".equals(code)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
							code = number;
						}else if(!"".equals(number)&&"".equals(code)){
							code = number;
						}else if("".equals(number)&&!"".equals(code)){
							number = code;
						}

						if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
						}
						String total = getString(details, "total");
						String time = getString(details, "time");// 时间
						String entrance = getString(details, "entrance");// 入口
						String exit = getString(details, "exit");// 出口
						if ("".equals(total)) {
							total = "0.00";
						}
						//ocr增加字段
						String kind =  getString(details, "kind");// 发票消费类型
						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						if (invoiceId == 0) {
							String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,taxIncludedPrice,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, date, code, number, TOLLS_TYPE, df.format(Util.getDoubleValue(total,0.00)), userid, "1","2",
									FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind );
							// 获取发票id
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
							// 插入过路费发票明细表
							String insertToll = "insert into tollInvoice(mainid,time,entrance,export) values(?,?,?,?)";
							rs.executeUpdate(insertToll, invoiceId, time, entrance, exit);

							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
							insertLog=true;
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					}else if("20100".equals(type)){//国际小票
						bb.writeLog("国际小票", details);
						String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

						String store_name = getString(details, "store_name");//店名
						String time = getString(details, "time");//时间
						String subtotal = getString(details, "subtotal");//税前金额
						if("".equals(subtotal)){
							subtotal = "0.00";
						}
						String tax = getString(details, "tax");//税费
						if("".equals(tax)){
							subtotal = "0.00";
						}
						String discount = getString(details, "discount");//折扣
						String tips = getString(details, "tips");//小费
						String total = getString(details, "total");//总金额
						if("".equals(total)){
							total = "0.00";
						}
						String currency_code = getString(details, "currency_code");//币种
						String xftype = getString(details, "type");//消费类型
						String number = MultiInvoiceUtil.randomInvoiceNumber();
						String code = number;
						String insertInvoice = " insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,"+
								" taxIncludedPrice,userid_new,authenticity,checkStatus,status,priceWithoutTax,tax,entryTime,invoiceSource_new,imageID) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						rs.executeUpdate(insertInvoice, date,code, number, 13,total,userid,"1","2",FnaInvoiceCommon.INIT_STATUS,subtotal,tax,entryTime,FnaInvoiceCommon.INVOICESOURCE_OCR,imageID);
						//获取发票id
						invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
						//插入小票发票明细表
						String insertToll = "insert into smallInvoice(mainid,storename,time,discount,tips,currency_code,type) values(?,?,?,?,?,?,?)";
						rs.executeUpdate(insertToll, invoiceId,store_name,time,discount,tips,currency_code,xftype);

						//插入明细
						InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
						insertLog=true;

						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					}else if("10900".equals(type)){//可报销的其他发票
						bb.writeLog("可报销其他发票", details);
						String code = Util.null2String(getString(details, "code"));
						String number = Util.null2String(getString(details, "number"));
						String kind = Util.null2String(getString(details, "kind"));
						String total = Util.null2String(getString(details, "total"));
						String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");


						//如果都为空，默认识别失败
						if("".equals(code) && "".equals(number) && "".equals(total) && "".equals(date)) {
							uploadMsg.append(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(517365,weaver.general.ThreadVarLanguage.getLang())+"");
							continue;
						}






						if("".equals(number)&&"".equals(code)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
							code = number;
						}else if(!"".equals(number)&&"".equals(code)){
							code = number;
						}else if("".equals(number)&&!"".equals(code)){
							number = code;
						}

						if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
						}
						if ("".equals(total)) {
							total = "0.00";
						}

						String seller = MultiInvoiceUtil.getString(details, "seller");
						String seller_tax_id = MultiInvoiceUtil.getString(details, "seller_tax_id");
						String buyer = MultiInvoiceUtil.getString(details, "buyer");
						String buyer_tax_id = MultiInvoiceUtil.getString(details, "buyer_tax_id");
						String seller_addr_tel = MultiInvoiceUtil.getString(details, "seller_addr_tel");
						String seller_bank_account = MultiInvoiceUtil.getString(details, "seller_bank_account");
						String buyer_addr_tel = MultiInvoiceUtil.getString(details, "buyer_addr_tel");
						String buyer_bank_account = MultiInvoiceUtil.getString(details, "buyer_bank_account");

						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						if (invoiceId == 0) {
							String insertInvoice = " insert into fnaInvoiceLedger(invoiceCode,invoiceNumber,invoiceType,billingDate,"+
									" taxIncludedPrice,kind,userid_new,authenticity,checkStatus,status,entryTime,invoiceSource_new,imageID," +
									" seller,salesTaxNo,purchaser,purchaserTaxNo) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, code, number,OTHERS_TYPE,date,total,kind,userid,"1","2",FnaInvoiceCommon.INIT_STATUS,entryTime,FnaInvoiceCommon.INVOICESOURCE_OCR,imageID,seller,seller_tax_id,buyer,buyer_tax_id);

							// 获取发票id
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
							InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0, invoiceId, "","", seller_addr_tel, buyer_addr_tel, seller_bank_account, buyer_bank_account);
							insertLog=true;
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					}else if("10902".equals(type)){//完税证明
						bb.writeLog("完税证明", details);
						String code = Util.null2String(getString(details, "code"));
						String number = Util.null2String(getString(details, "number"));
						String total = Util.null2String(getString(details, "total"));
						String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

						String buyer = Util.null2String(getString(details, "buyer"));
						String buyer_tax_id = Util.null2String(getString(details, "buyer_tax_id"));

						if("".equals(number)&&"".equals(code)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
							code = number;
						}else if(!"".equals(number)&&"".equals(code)){
							code = number;
						}else if("".equals(number)&&!"".equals(code)){
							number = code;
						}

						if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
						}
						if ("".equals(total)) {
							total = "0.00";
						}
						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						if (invoiceId == 0) {
							String insertInvoice = " insert into fnaInvoiceLedger(invoiceCode,invoiceNumber,invoiceType,billingDate,"+
									" taxIncludedPrice,purchaser,purchaserTaxNo,userid_new,authenticity,checkStatus,status,entryTime,invoiceSource_new,imageID) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice, code, number,TAX_CERTIFICATE_TYPE ,date,total,buyer,buyer_tax_id,userid,"1","2",FnaInvoiceCommon.INIT_STATUS,entryTime,FnaInvoiceCommon.INVOICESOURCE_OCR,imageID);

							// 获取发票id
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
							insertLog=true;
						}

						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					}else if("19".equals(type)){//区块链发票

						bb.writeLog("区块链发票", details);
						String number = getString(details, "number");
						String code =getString(details, "code");
						String date =getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
						String pretax_amount = getString(details, "pretax_amount");

						if("".equals(pretax_amount)){
							pretax_amount = "0.00";
						}
						if("".equals(number)&&"".equals(code)){
							number = MultiInvoiceUtil.randomInvoiceNumber();
							code = number;
						}else if(!"".equals(number)&&"".equals(code)){
							code = number;
						}else if("".equals(number)&&!"".equals(code)){
							number = code;
						}


						if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
							String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
									.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
							uploadMsg.append(msg);
							uploadMsg.append("\n");
							invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
						}
						String check_code = getString(details, "check_code");
						String total = getString(details, "total");
						if("".equals(total)){
							total = "0.00";
						}
						String tax = getString(details, "tax");
						if("".equals(tax)){
							tax = "0.00";
						}
						DecimalFormat dfTaxRate = new DecimalFormat("###0");
						double taxRate =0;
						if(!"0.00".equals(tax) && !"0.00".equals(pretax_amount)){
							taxRate = (Util.getDoubleValue(tax)/Util.getDoubleValue(pretax_amount))*100;
						}

						String seller = getString(details, "seller");
						String seller_tax_id = getString(details, "seller_tax_id");
						String buyer = getString(details, "buyer");
						String buyer_tax_id = getString(details, "buyer_tax_id");
						String category = getString(details, "category");//种类
						String kind = getString(details, "kind");//发票消费类型
						String seller_addr_tel = MultiInvoiceUtil.getString(details, "seller_addr_tel");
						String seller_bank_account = MultiInvoiceUtil.getString(details, "seller_bank_account");
						String buyer_addr_tel = MultiInvoiceUtil.getString(details, "buyer_addr_tel");
						String buyer_bank_account = MultiInvoiceUtil.getString(details, "buyer_bank_account");

						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						if (invoiceId == 0) {
							rs.executeUpdate("insert into FnaInvoiceLedger(invoiceCode,invoiceNumber,billingDate,priceWithoutTax,tax,taxRate,"
											+ " checkcode,taxIncludedPrice,seller,salesTaxNo,purchaser,purchaserTaxNo,userid_new,status,authenticity,checkStatus," +
											" invoiceType,imageID,invoiceSource_new,entryTime,category,kind) " +
											"values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
									code, number, date, pretax_amount, tax, dfTaxRate.format(taxRate),
									check_code, total, seller, seller_tax_id, buyer, buyer_tax_id, userid, FnaInvoiceCommon.INIT_STATUS, "1", "2",
									BLOCKCHAIN_TYPE, imageID, FnaInvoiceCommon.INVOICESOURCE_OCR, entryTime, category, kind);
							// 获取发票id
							invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
							//插入明细
							InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId, Constants.INVOICESERVICEYYPE.get(type), df.format(Util.getDoubleValue(pretax_amount, 0.00)), dfTaxRate.format(taxRate),tax, 1, df.format(Util.getDoubleValue(pretax_amount, 0.00)), df.format(Util.getDoubleValue(pretax_amount, 0.00)), "", "");
							InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0, invoiceId, "","", seller_addr_tel, buyer_addr_tel, seller_bank_account, buyer_bank_account);
							insertLog=true;
						}
						if(!"".equals(invoiceIds)){
							invoiceIds += ",";
						}
						invoiceIds += invoiceId;
					}else{
						uploadMsg.append(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(517365,weaver.general.ThreadVarLanguage.getLang())+"");
					}

					//插入日志
					if(insertLog) {

						//生成发票文档
						ImageDocUtil.updateImageDocId(String.valueOf(invoiceId));

						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = new HashMap<String, String>();
						Map<String, String> afterMap = fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceId), labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user, ipAdress, "0", String.valueOf(invoiceId), "0",
								beforeMap, afterMap, labelIdMap);
					}
				}



				if(uploadMsg.length()==0){
					uploadMsg.append(SystemEnv.getHtmlLabelName(25388, user.getLanguage()));//上传成功
				}
				result.put("uploadMsg", imagefilename+uploadMsg.toString());
			}else{
				throw new Exception(imagefilename+"仅限上传jpg、jpeg、gif、png、pdf、ofd格式！");
			}
			result.put("status", "1");
			result.put("invoiceIds", invoiceIds);
		}catch (Exception e){
			new BaseBean().writeLog("e", e);
			result.put("status", "-1");
			result.put("uploadMsg", e.getMessage());
		}

		return result;
	}

	/**
	 * 增值税验票
	 * @param invoiceId
	 * @return
	 */
	public static String authenticityCheck(int invoiceId,User user,String ipAdress) throws Exception{
		String errorMsg = "";
		DecimalFormat df = new DecimalFormat("##########################0.00");
		RecordSet rs = new RecordSet();
		rs.executeQuery("select * from FnaInvoiceLedger where id=?",invoiceId);
		String invoiceType ="";
		String invoiceCode = "";
		String invoiceNumber = "";
		String billingDate = "";
		String checkcode = "";
		String priceWithoutTax = "";
		String taxIncludedPrice = "";
		if(rs.next()){
			invoiceType=Util.null2String(rs.getString("invoiceType"));
			invoiceCode=Util.null2String(rs.getString("invoiceCode"));
			invoiceNumber=Util.null2String(rs.getString("invoiceNumber"));
			billingDate=Util.null2String(rs.getString("billingDate")).replaceAll("-","");
			checkcode=Util.null2String(rs.getString("checkcode"));
			priceWithoutTax=Util.null2String(rs.getString("priceWithoutTax"));
			taxIncludedPrice=Util.null2String(rs.getString("taxIncludedPrice"));
		}
		String result = "";
		if("1".equals(invoiceType) || "15".equals(invoiceType) || "16".equals(invoiceType) || "20".equals(invoiceType)){//普票
			if(!"".equals(invoiceCode)&&!"".equals(invoiceNumber)&&!"".equals(billingDate)&&!"".equals(checkcode)){
				result = "01,04,"+invoiceCode+","+invoiceNumber+",0.00,"+billingDate+",00000000000"+checkcode+",0000,";
			}
		}else if("2".equals(invoiceType) || "12".equals(invoiceType) || "21".equals(invoiceType)){//专票
			result = "01,01,"+invoiceCode+","+invoiceNumber+","+priceWithoutTax+","+billingDate+","+"000000000000000,0000,";
		}else if("32".equals(invoiceType)||"33".equals(invoiceType)){
			result = "01,01,"+invoiceCode+","+invoiceNumber+","+taxIncludedPrice+","+billingDate+","+"000000000000000,0000,";
		}
		if(!"".equals(result)){
			//插入日志1
			Map<String, String> labelIdMap = new HashMap<String, String>();
			Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceId),labelIdMap);

			FnaInvoiceCommon fnaInvoiceCommon = new FnaInvoiceCommon();
			FnaAbstractInterface fnaAbstractInterface = fnaInvoiceCommon.getInterface(user);
			JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result,null);
			int checkstatus = resultObj.getInt("status");
			if(checkstatus == 0){//失败
				rs.executeUpdate("update fnaInvoiceLedger set authenticity=2,checkStatus=3 where id=?",invoiceId);
				if(resultObj.containsKey("errMsg")){
					errorMsg = resultObj.getString("errMsg");
				}else{
					errorMsg = SystemEnv.getHtmlLabelName(509478, user.getLanguage());//查验失败!
				}
			}else{
				//首先判断当前发票的发票类型
				if(VAT_SPECIAL_TYPE.equals(invoiceType) || VAT_ORDINARY_TYPE.equals(invoiceType) || VAT_Electronic_Type.equals(invoiceType) || VAT_ORDINARY_Volume_TYPE.equals(invoiceType) || VAT_Electronic_Tolls_Type.equals(invoiceType)
						 || VAT_Electronic_SPECIAL_Type.equals(invoiceType)||VAT_ELEC_TYPE.equals(invoiceType)||VAT_GENE_TYPE.equals(invoiceType)){//增值税发票
					String purchaser = resultObj.getString("_purchaser");
					String _purchaserTaxNo = resultObj.getString("_purchaserTaxNo");
					String seller = resultObj.getString("_seller");
					String _salesTaxNo = resultObj.getString("_salesTaxNo");//销售方纳税人识别号
					String taxRate = Util.getDoubleValue(resultObj.getString("_taxRate"),0.00)+"";
					String tax = resultObj.getString("_tax");
					String _priceWithoutTax = resultObj.getString("_priceWithoutTax");
					String _invoiceServiceYype = resultObj.getString("_invoiceServiceYype");
					String _billingDate1 = resultObj.getString("_billingDate");
					String _taxIncludedPrice = resultObj.getString("_taxIncludedPrice");
					String _invoiceNumber = resultObj.getString("_invoiceNumber");
					//String _invoicecode = resultObj.getString("_invoicecode");
					String _checkCode = resultObj.getString("_checkCode");
					String checkCodeSix = "";
					String _invoicecode="";
					if(VAT_ELEC_TYPE.equals(invoiceType)||VAT_GENE_TYPE.equals(invoiceType)){
						_invoicecode=_invoiceNumber;
					}else {
						_invoicecode = resultObj.getString("_invoicecode");
					}
					if(_checkCode.length()>6){
						checkCodeSix = _checkCode.substring(_checkCode.length()-6);
					}
					String remark = resultObj.getString("_remark");
					String sellerAddress = resultObj.getString("_sellerAddress");
					String purchaserAddress = resultObj.getString("_purchaserAddress");
					String salesBank = resultObj.getString("_salesBank");
					String purchaserBank = resultObj.getString("_purchaserBank");
					String _invoiceType = resultObj.getString("_invoiceType");

					if(!fnaInvoiceCommon.ifExistAuthenticity2(_invoiceNumber, _invoicecode, new RecordSet())){
						//判断纳税人识别号是否维护
						boolean protectInvoiceTaxpayerNumber = FnaInvoiceCommon.protectInvoiceTaxpayerNumber(purchaser,_purchaserTaxNo);
						if(protectInvoiceTaxpayerNumber){

							rs.executeUpdate("update fnaInvoiceLedger set invoiceType=?,checkCode=?,tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=1,checkStatus=1,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
											"salesTaxNo=?,purchaserTaxNo=?,invoiceNumber=?,invoiceCode=? where id=?"
									,_invoiceType,_checkCode,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,taxRate,_priceWithoutTax,_invoiceServiceYype,
									_salesTaxNo,_purchaserTaxNo,_invoiceNumber,_invoicecode,invoiceId);
							InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,invoiceId,remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);
							JSONArray detaildata = resultObj.getJSONArray("detaildata");
							InvoiceUtil.saveVATInvoiceDetail(detaildata,String.valueOf(invoiceId));
						}else{
							rs.executeUpdate("update fnaInvoiceLedger set authenticity=2,checkStatus=3 where id=?",invoiceId);
							errorMsg = SystemEnv.getHtmlLabelName(390260,user.getLanguage());
						}
					}
				}else if(MOTORVEHICLESALES_TYPE.equals(invoiceType)){//机动车销售统一发票
					//获取发票信息
					String taxIncludedPriceTrue = df.format(Util.getDoubleValue(resultObj.getString("_taxIncludedPrice"),0.00));
					String priceWithoutTaxTrue = df.format(Util.getDoubleValue(resultObj.getString("_priceWithoutTax"),0.00));
					String taxTrue = df.format(Util.getDoubleValue(resultObj.getString("_tax"),0.00));
					String taxRateTrue = df.format(Util.getDoubleValue(resultObj.getString("_taxRate"),0.00));
					String invoiceNumberTrue = resultObj.getString("_invoiceNumber");
					String invoicecodeTrue = resultObj.getString("_invoicecode");
					String purchaserTrue = resultObj.getString("_purchaser");
					String sellerTrue = resultObj.getString("_seller");
					String purchaserTaxNoTrue = resultObj.getString("_purchaserTaxNo");
					String salesTaxNoTrue = resultObj.getString("_salesTaxNo");
					String billingDateTrue = resultObj.getString("_billingDate");

					String remark = resultObj.getString("_remark");
					String sellerAddress = resultObj.getString("_sellerAddress");
					String purchaserAddress = resultObj.getString("_purchaserAddress");
					String salesBank = resultObj.getString("_salesBank");
					String purchaserBank = resultObj.getString("_purchaserBank");

					//机动车销售统一发票明细信息
					String machine_code = resultObj.getString("_machine_code");
					String machine_number = resultObj.getString("_machine_number");
					String tax_authorities = resultObj.getString("_tax_authorities");
					String tax_authorities_code = resultObj.getString("_tax_authorities_code");
					String car_code = resultObj.getString("_car_code");
					String car_engine_code = resultObj.getString("_car_engine_code");
					String car_model = resultObj.getString("_car_model");
					String certificate_number = resultObj.getString("_certificate_number");


					rs.executeUpdate("update fnaInvoiceLedger set billingDate=?,invoiceCode=?,invoiceNumber=?,invoiceType=?,seller=?,purchaser=?,salesTaxNo=?,purchaserTaxNo=?," +
									"priceWithoutTax=?,tax=?,taxRate=?,taxIncludedPrice=?,authenticity=?,checkStatus=? where id=?"
							,billingDateTrue,invoicecodeTrue,invoiceNumberTrue,invoiceType,sellerTrue,purchaserTrue,salesTaxNoTrue,purchaserTaxNoTrue,
							priceWithoutTaxTrue,taxTrue,taxRateTrue,taxIncludedPriceTrue,1,1,invoiceId);
					rs.executeQuery("select 1 from motor_VehicleInvoice where mainid=?",invoiceId);
					if(rs.next()){
						rs.executeUpdate("update motor_VehicleInvoice set machine_code=?,machine_number=?,tax_authorities=?,tax_authorities_code=?,car_code=?,car_engine_code=?,car_model=?,certificate_number=? where mainid=?",
								machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number,invoiceId);

					}else{
						rs.executeUpdate("insert into motor_VehicleInvoice (mainid,machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number) values(?,?,?,?,?,?,?,?,?)",
								invoiceId,machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number);

					}
					//保存FnaInvoiceLedgerDtl表信息
					InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,invoiceId,remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);

					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(invoiceType),priceWithoutTaxTrue,taxRateTrue,taxTrue,1,priceWithoutTaxTrue,priceWithoutTaxTrue,"","");

				}
			}

			//插入日志2
			Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceId),labelIdMap);
			fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",String.valueOf(invoiceId),"1",
					beforeMap,afterMap,labelIdMap);
		}
		return errorMsg;
	}

	/**
	 * 获取发票信息
	 * @param id
	 * @return
	 */
	public static String[] getInvoiceData(String invoiceNumber,String invoiceCode){
		RecordSet rs = new RecordSet();
		String[] data = new String[6];
		String sql = "select id,billingDate,taxIncludedPrice,invoiceType,checkCode,invoiceCode from fnaInvoiceLedger where invoiceNumber = ? and invoiceCode = ? ";
		rs.executeQuery(sql, invoiceNumber, invoiceCode);
		String id = "0";
		String billingDate = "";
		String taxIncludedPrice = "";
		String invoiceType = "";
		String checkCode = "";

		if(rs.next()){
			id = Util.null2String(rs.getString("id"));
			billingDate = Util.null2String(rs.getString("billingDate"));
			taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
			invoiceType = Util.null2String(rs.getString("invoiceType"));
			checkCode = Util.null2String(rs.getString("checkCode"));

		}
		data[0] = billingDate;
		data[1] = taxIncludedPrice;
		data[2] = invoiceType;
		data[3] = id;
		data[4] = checkCode;
		data[5] = invoiceCode;
		return data;
	}

	/**
	 * 校验日期格式
	 * @param date
	 * @return
	 */
	private static boolean checkDate(String date) {
		try {
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			format.setLenient(false);
			format.parse(date);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	/**
	 * 获取json数据
	 * @param json
	 * @param key
	 * @return
	 */
	public static String getString(JSONObject json, String key) {
		if (json.containsKey(key)) {
			return json.getString(key);
		}
		return "";
	}

	/**
	 * 获取当前时间
	 * @return
	 */
	private static String getDate(){
		return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
	}



}
