package com.engine.fna.util;


import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.api.fna.util.FnaConstant;
import jxl.read.biff.Record;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringEscapeUtils;
import weaver.conn.RecordSet;
import weaver.fna.invoice.Constants;
import weaver.fna.invoice.common.FnaAbstractInterface;
import weaver.fna.invoice.common.FnaInvoiceCommon;
import weaver.fna.invoice.utils.*;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Author: lb2018
 * @Description:移动端微报账ocr识别录入发票工具类
 * @Date: 2020/3/15 14:29
 */
public class EnterInvoiceByOcrUtil {


    /**发票不存在*/
    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 INTERNATIONAL_RECEIPTS = "13";
    /**增值税电子普通发票*/
    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 final int AUTHENTICITY_UNDETERMINED = 0;
    /**真*/
    private static final int AUTHENTICITY_TRUE = 1;
    /**伪*/
    private static final int AUTHENTICITY_FALSE = 2;


    /*待定*/
    private static final int checkStatus_0 = 0;
    /*有效未查验*/
    private static final int checkStatus_1 = 1;
    /*有效已查验*/
    private static final int checkStatus_2 = 2;
    /*无效*/
    private static final int checkStatus_3 = 3;

    /**df*/
    private static DecimalFormat df = new DecimalFormat("##########################0.00");

    private static FnaLogSqlUtil fnaLogSqlUtil = new FnaLogSqlUtil();
    /**
     * ocr识别处理
     * @param ocrResult
     * @param user
     * @param imageBytes
     * @return
     */
    public JSONObject ocrHandle(JSONObject ocrResult, User user, byte[] imageBytes,String ipAdress)throws Exception{
        JSONObject rtnJson = new JSONObject();
        JSONArray invoiceArray = new JSONArray();
        try {
            String entryTime = Util.date(2);//录入时间
            BaseBean bb = new BaseBean();
            int status = ocrResult.getInt("status");
            if (status == Constants.ERROR_CODE) {
                throw new Exception(ocrResult.getString("errMsg"));
            }
            JSONObject postjson = JSONObject.fromObject(ocrResult.get("returnInfo"));
            bb.writeLog("postjson:", postjson);
            String result = postjson.getString("result");
            if (!"1".equals(result)) {
                FnaInvoiceCommon.saveFailLog(user.getUID(), 0, postjson.getString("message"));
                throw new Exception(postjson.getString("message"));
            }
            JSONArray identify_results_array = postjson.getJSONObject("response").getJSONObject("data")
                    .getJSONArray("identify_results");
            if (identify_results_array.size() == 0) {
                FnaInvoiceCommon.saveFailLog(user.getUID(), 0, SystemEnv.getHtmlLabelName(509482, user.getLanguage()));//识别结果为空!
                throw new Exception(SystemEnv.getHtmlLabelName(509482, user.getLanguage()));//识别结果为空!
            }
            int userid = user.getUID();
            RecordSet rs = new RecordSet();
            int identifyArraySize = identify_results_array.size();
            int imageID = 0;
            if (identifyArraySize == 1) {
                imageID = FnaInvoiceCommon.saveImage(imageBytes,user);
            }
            FnaInvoiceCommon fnaInvoiceCommon = new FnaInvoiceCommon();
            StringBuffer existsInvoiceSb = new StringBuffer();
            boolean existsInterface = InvoiceUtil.ifExistsInterface(user);
            for (int i = 0; i < identifyArraySize; i++) {
                JSONObject infoJson = new JSONObject();
                bb.writeLog("解析发票开始:" + i + "################################################");
                JSONObject identify_results = identify_results_array.getJSONObject(i);
                String type = identify_results.getString("type");
                if (identifyArraySize > 1) {
                    String region = identify_results.getString("region");
                    String orientation = identify_results.getString("orientation");
                    String[] regions = region.replace("[", "").replace("]", "").split(",");
                    int x = 0;
                    int y = 0;
                    int w = 0;
                    int h = 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);
                        if(!"".equals(cutImageBase64)){
                            infoJson.put("newImage",cutImageBase64);
                        }
                    }
                }else{
                    infoJson.put("newImage", "data:image/jpeg;base64,"+Base64.encodeBase64String(imageBytes));
                }



                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"));
			}




                bb.writeLog(Constants.INVOICETYPE.get(type));
                infoJson.put("invoiceType", type);
                infoJson.put("imageID",imageID);

                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)) {
                        number = randomInvoiceNumber();
                        code = number;
                    } else if (!"".equals(number) && "".equals(code)) {
                        code = number;
                    } else if ("".equals(number) && !"".equals(code)) {
                        number = 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));
                            existsInvoiceSb.append(msg);
                            existsInvoiceSb.append("\n");
                        }
                    }
                    
                    String invoiceType="";
					if("10100".equals(type)){
						invoiceType = VAT_SPECIAL_TYPE;
					}else if("21".equals(type)){
						invoiceType = VAT_Electronic_SPECIAL_Type;
					}

                    double totalAmount = Util.getDoubleValue(getString(details, "total"), 0.00);
                    boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
                    if (existsInterface && needCheck) {
                        infoJson.put("needCheck", true);
                    } else {
                        infoJson.put("needCheck", false);
                    }
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    invoiceId = InvoiceUtil.saveVATInvoice(details, user, invoiceType, imageID, existsInterface, needCheck,ipAdress);
                    infoJson.put("invoiceNumber", number);
                    infoJson.put("invoiceId", invoiceId);
                    addShowInfo(infoJson, number, code);
                } else if ("10107".equals(type)) {// 新型专票（电票）//32专用33普通
                    String number = details.getString("number");
                    //String code = details.getString("code");
                    String code=number;
                    String invoiceType="";
                    if("10107".equals(type)){
                        invoiceType = VAT_ELEC_TYPE;
                    }
                    if(!"".equals(number)&&number.length()>16){
                        if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
                            String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
                                    .replace("${invoiceType}", Constants.INVOICETYPE.get(type));
                            existsInvoiceSb.append(msg);
                            existsInvoiceSb.append("\n");
                        }
                    }
                    double totalAmount =Util.getDoubleValue(getString(details, "total"),0.00);
                    boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
                    if(existsInterface && needCheck){
                        //保存发票
                        invoiceId = InvoiceUtil.saveVATInvoice(details, user, invoiceType, imageID, existsInterface, needCheck,ipAdress);
                        infoJson.put("needCheck", true);
                        infoJson.put("invoiceNumber", number);
                        infoJson.put("invoiceId", invoiceId);
                        addShowInfo(infoJson, number, code);

                    }else{
                        invoiceId = InvoiceUtil.saveVATInvoice(details, user, invoiceType, imageID, existsInterface, needCheck,ipAdress);
                        infoJson.put("needCheck", false);
                        infoJson.put("invoiceNumber", number);
                        infoJson.put("invoiceId", invoiceId);
                        addShowInfo(infoJson, number, code);
                    }
                }else if ("10108".equals(type)) {// 新型专票（电票）//32专用33普通
                    String number = details.getString("number");
                    //String code = details.getString("code");
                    String code=number;
                    String invoiceType=VAT_GENE_TYPE;

                    if(!"".equals(number)&&number.length()>16){
                        if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
                            String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
                                    .replace("${invoiceType}", Constants.INVOICETYPE.get(type));
                            existsInvoiceSb.append(msg);
                            existsInvoiceSb.append("\n");
                        }
                    }
                    double totalAmount =Util.getDoubleValue(getString(details, "total"),0.00);
                    boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
                    if(existsInterface && needCheck){
                        infoJson.put("needCheck", true);
                        invoiceId = InvoiceUtil.saveVATInvoice(details, user, invoiceType, imageID, existsInterface, needCheck,ipAdress);                  
                        infoJson.put("invoiceNumber", number);
                        infoJson.put("invoiceId", invoiceId);
                        addShowInfo(infoJson, number, code);
                    }else{
                        infoJson.put("needCheck", false);
                        invoiceId = InvoiceUtil.saveVATInvoice(details, user, invoiceType, imageID, existsInterface, needCheck,ipAdress);
                        infoJson.put("invoiceNumber", number);
                        infoJson.put("invoiceId", invoiceId);
                        addShowInfo(infoJson, number, code);
                    }
                }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)) {
                        number = randomInvoiceNumber();
                        code = number;
                    } else if (!"".equals(number) && "".equals(code)) {
                        code = number;
                    } else if ("".equals(number) && !"".equals(code)) {
                        number = 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));
                            existsInvoiceSb.append(msg);
                            existsInvoiceSb.append("\n");
                        }
                    }
                    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(getString(details, "total"), 0.00);
                    boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);

                    if (existsInterface && needCheck) {
                        infoJson.put("needCheck", true);
                    } else {
                        infoJson.put("needCheck", false);

                    }
                    invoiceId = InvoiceUtil.saveVATInvoice(details, user, invoiceType, imageID, existsInterface, needCheck,ipAdress);

                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    infoJson.put("invoiceNumber", number);
                    infoJson.put("invoiceId", invoiceId);
                    addShowInfo(infoJson, number, code);
                } else if ("10104".equals(type)) {// 机动车销售统一发票
                    String number = details.getString("number");
                    String code = details.getString("code");

                    if ("".equals(number) && "".equals(code)) {
                        number = randomInvoiceNumber();
                        code = number;
                    } else if (!"".equals(number) && "".equals(code)) {
                        code = number;
                    } else if ("".equals(number) && !"".equals(code)) {
                        number = 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));
                            existsInvoiceSb.append(msg);
                            existsInvoiceSb.append("\n");
                        }
                    }

                    double totalAmount = Util.getDoubleValue(getString(details, "total"), 0.00);
                    boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
                    if (existsInterface && needCheck) {
                        infoJson.put("needCheck", true);
                    } else {
                        infoJson.put("needCheck", false);
                    }


                    String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

                    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(MultiInvoiceUtil.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;
                    }



                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    infoJson.put("invoiceNumber", number);
                    infoJson.put("invoiceId", invoiceId);
                    addShowInfo(infoJson, number, code);
                } else if ("10105".equals(type)) {// 二手车销售统一发票
                    String number = Util.null2String(getString(details, "number"));
                    String code = getString(details, "code");
                    if ("".equals(number) && "".equals(code)) {
                        number = 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));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }
                    String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");


                    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");// 厂牌型号
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    infoJson.put("invoiceNumber", number);
                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number, code)[3])) {
                        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;
                    }
                    addShowInfo(infoJson, number, code);
                } else if ("10200".equals(type)) {// 定额发票

                    String number = Util.null2String(getString(details, "number"));
                    String code = getString(details, "code");
                    if ("".equals(number) && "".equals(code)) {
                        number = 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));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }
                    String total = getString(details, "total");
                    if ("".equals(total)) {
                        total = "0.00";
                    }
                    String billingDate = "";
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    infoJson.put("invoiceNumber", number);

                    //ocr增加字段
                    String kind = getString(details, "kind");
                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number, code)[3])) {
                        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;
                    }
                    addShowInfo(infoJson, number, code);
                } else if ("10400".equals(type)) {// 机打发票
                    String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

                    String number = Util.null2String(getString(details, "number"));
                    String code = getString(details, "code");
                    if ("".equals(number) && "".equals(code)) {
                        number = 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));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }
                    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");//发票消费类型
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    infoJson.put("invoiceNumber", number);
                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number, code)[3])) {
                        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;
                    }
                    addShowInfo(infoJson, number, code);
                } else if ("10500".equals(type)) {// 出租车发票
                    String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

                    String code = getString(details, "code");
                    String number = Util.null2String(getString(details, "number"));
                    if ("".equals(number) && "".equals(code)) {
                        number = 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));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }


                    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");// 发票消费类型
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    infoJson.put("invoiceNumber", number);
                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number, code)[3])) {
                        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;
                    }
                    addShowInfo(infoJson, number, code);
                } else if ("10503".equals(type)) {// 火车票

                    String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

                    String number = Util.null2String(getString(details, "serial_number"));
                    if ("".equals(number)) {
                        number = randomInvoiceNumber();
                    }
                    if (fnaInvoiceCommon.ifExistAuthenticity(number, number, rs)) {
                        String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
                                .replace("${invoiceType}", Constants.INVOICETYPE.get(type));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }
                    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");// 发票消费类型
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    infoJson.put("invoiceNumber", number);
                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number, number)[3])) {
                        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;
                    }
                    addShowInfo(infoJson, number, number);
                } else if ("10505".equals(type)) {// 客运汽车

                    String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

                    String code = getString(details, "code");
                    String number = Util.null2String(getString(details, "number"));
                    if ("".equals(number) && "".equals(code)) {
                        number = 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));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }
                    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");// 发票消费类型
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    infoJson.put("invoiceNumber", number);
                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number, code)[3])) {
                        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;
                    }
                    addShowInfo(infoJson, number, code);
                } else if ("10506".equals(type)) {// 航空运输电子客票行程单

                    String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

                    String number = Util.null2String(getString(details, "number"));
                    if ("".equals(number)) {
                        number = randomInvoiceNumber();
                    }
                    if (fnaInvoiceCommon.ifExistAuthenticity(number, number, rs)) {
                        String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
                                .replace("${invoiceType}", Constants.INVOICETYPE.get(type));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }
                    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");// 发票消费类型
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    infoJson.put("invoiceNumber", number);
                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number, number)[3])) {
                        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;
                    }
                    addShowInfo(infoJson, number, number);
                } else if ("10507".equals(type)) {// 过路费发票

                    String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

                    String code = getString(details, "code");
                    String number = Util.null2String(getString(details, "number"));
                    if ("".equals(number) && "".equals(code)) {
                        number = 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));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }
                    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");// 发票消费类型
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    infoJson.put("invoiceNumber", number);
                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number, code)[3])) {
                        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;
                    }
                    addShowInfo(infoJson, number, code);
                } else if ("20100".equals(type)) {//国际小票

                    String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

                    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 = 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;
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    addShowInfo(infoJson, number, code);

                }else if("10900".equals(type)){//可报销的其他发票
                    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("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

                    //如果都为空，默认识别失败
                    if("".equals(code) && "".equals(number) && "".equals(total) && "".equals(date)){
                        FnaInvoiceCommon.saveFailLog(user.getUID(), 0, "识别失败");
                        if(identifyArraySize==1){
                            throw new Exception("识别失败");
                        }else{
                            continue;
                        }
                    }


                    if("".equals(number)&&"".equals(code)){
                        number = 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));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }
                    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");

                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
                        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;
                    }
                    infoJson.put("invoiceNumber", number);
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    addShowInfo(infoJson, number,code);
                }else if("10902".equals(type)){//完税证明

                    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 date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

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

                    if("".equals(number)&&"".equals(code)){
                        number = 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));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }
                    if ("".equals(total)) {
                        total = "0.00";
                    }
                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
                        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;
                    }
                    infoJson.put("invoiceNumber", number);
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    addShowInfo(infoJson, number,code);

                }else if("19".equals(type)){//区块链发票

                    String number = getString(details, "number");
                    String code =getString(details, "code");
                    String date =getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
                    //String date = getString(details, "date").replace(SystemEnv.getHtmlLabelName(523944,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523943,user.getLanguage()), "-").replace(SystemEnv.getHtmlLabelName(523285,user.getLanguage()), "");

                    String pretax_amount = getString(details, "pretax_amount");

                    if("".equals(pretax_amount)){
                        pretax_amount = "0.00";
                    }
                    if("".equals(number)&&"".equals(code)){
                        number = 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));
                        existsInvoiceSb.append(msg);
                        existsInvoiceSb.append("\n");
                    }

                    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";
                    }
                    String taxRate ="0.00";
                    if(!"0.00".equals(tax) && !"0.00".equals(pretax_amount)){
                        taxRate = df.format((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");

                    if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
                        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, 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)), 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;
                    }
                    infoJson.put("invoiceNumber", number);
                    infoJson.put("description", Constants.INVOICETYPE.get(type));
                    addShowInfo(infoJson, number,code);
                } else {
                    FnaInvoiceCommon.saveFailLog(user.getUID(), 0, "识别失败");
                    if (identifyArraySize == 1) {
                        throw new Exception("识别失败");
                    } else {
                        continue;
                    }
                }
                invoiceArray.add(infoJson);

                //插入日志
                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);
                }
            }
            rtnJson.put("flag", true);
            rtnJson.put("data", invoiceArray);
            rtnJson.put("exisdatatsInvoiceSb", existsInvoiceSb.toString());
            rtnJson.put("belongs",true);//是自己的发票

        }catch (Exception e){
            JSONObject infoJson = new JSONObject();
            infoJson.put("newImage", "data:image/jpeg;base64,"+Base64.encodeBase64String(imageBytes));
            invoiceArray.add(infoJson);
            rtnJson.put("data", invoiceArray);
            rtnJson.put("flag", false);
            rtnJson.put("belongs",true);//是自己的发票
        }
        //new BaseBean().writeLog("rtnJson==="+rtnJson);
        return rtnJson;
    }


    public JSONObject invoiceCheck(Map<String,Object> params, User user,String ipAdress) throws Exception {
        String imageId = Util.null2String(params.get("imageID"));
        String invoiceType = Util.null2String(params.get("invoiceType"));
        String invoiceNumber = Util.null2String(params.get("invoiceNumber"));
        String invoiceCode = Util.null2String(params.get("invoiceCode"));
        String billingDate = Util.null2String(params.get("billingDate"));
        String priceWithoutTax = df.format(Util.getDoubleValue((String)params.get("priceWithoutTax"),0.00));
        String checkCode = Util.null2String(params.get("checkCode"));
        String taxIncludedPrice =df.format(Util.getDoubleValue((String)params.get("taxIncludedPrice"),0.00));



        String entryTime = Util.date(2);//录入时间
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("imageID", imageId);



        FnaInvoiceCommon fnaInvoiceCommon = new FnaInvoiceCommon();
        RecordSet rs = new RecordSet();
        String[] invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
        //校验是否是自己的发票
        checkInvoiceBelongs(user,invoiceData[3]);

        if(!"".equals(invoiceNumber) && fnaInvoiceCommon.ifExistAuthenticity2(invoiceNumber,invoiceCode,rs)){
            jsonObject.put("flag", true);
            jsonObject.put("checkStatus","1");
            jsonObject.put("invoiceNumber", invoiceNumber);
            jsonObject.put("billingDate",invoiceData[0]);
            jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
            jsonObject.put("taxIncludedPrice", invoiceData[1]);
            jsonObject.put("invoiceId", invoiceData[3]);

            return jsonObject;
        }
        if("10100".equals(invoiceType)||"21".equals(invoiceType)) {//增值税专用发票
            if ("".equals(invoiceNumber) || "".equals(invoiceCode) || "".equals(billingDate) || "".equals(priceWithoutTax)) {
                if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                    if ("".equals(priceWithoutTax)) {
                        priceWithoutTax = "0.00";
                    }
                    if ("".equals(taxIncludedPrice)) {
                        taxIncludedPrice = "0.00";
                    }
                    if("10100".equals(invoiceType)){
                        invoiceType = VAT_SPECIAL_TYPE;
                    }else if("21".equals(invoiceType)){
                        invoiceType = VAT_Electronic_SPECIAL_Type;
                    }
                    String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate," +
                            " tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                    rs.executeUpdate(insertInvoice, billingDate, invoiceCode, invoiceNumber, invoiceType, Constants.INVOICETYPE.get(invoiceType), priceWithoutTax,
                            0.00, 0.00, df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)), AUTHENTICITY_UNDETERMINED, checkStatus_0,
                            user.getUID(), FnaInvoiceCommon.INIT_STATUS, imageId, FnaInvoiceCommon.INVOICESOURCE_OCR, entryTime);

                    invoiceData = getInvoiceData(invoiceNumber, invoiceCode);
                    //生成发票文档
                    ImageDocUtil.updateImageDocId(invoiceData[3]);
                    //插入日志
                    Map<String, String> labelIdMap = new HashMap<String, String>();
                    Map<String, String> beforeMap = new HashMap<String, String>();
                    Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                    fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                            beforeMap,afterMap,labelIdMap);
                }

                jsonObject.put("flag", true);
                jsonObject.put("checkStatus", "0");
                jsonObject.put("invoiceNumber", invoiceNumber);
                jsonObject.put("billingDate", invoiceData[0]);
                jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                jsonObject.put("invoiceId", invoiceData[3]);
                return jsonObject;
            } else {
                String result = "01,01," + invoiceCode + "," + invoiceNumber
                        + "," + priceWithoutTax
                        + "," + billingDate.replaceAll("-", "")
                        + ",,1111,";

                FnaAbstractInterface fnaAbstractInterface = new FnaInvoiceCommon().getInterface(user);
                JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result, null);
                int checkstatus = resultObj.getInt("status");
                
				int invType = InvoiceUtil.recoginizeInvoiceType(invoiceCode);
				if(invType==1){
					invoiceType = "2";
				}else if(invType==21){
					invoiceType = "21";
				}
				
                if (checkstatus == 0) {//验票失败
                    if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                        String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate," +
                                " tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        rs.executeUpdate(insertInvoice, billingDate, invoiceCode, invoiceNumber, invoiceType, Constants.INVOICETYPE.get(invoiceType), priceWithoutTax,
                                0.00, 0.00, df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)), AUTHENTICITY_FALSE, checkStatus_3,
                                user.getUID(), FnaInvoiceCommon.INIT_STATUS, imageId, FnaInvoiceCommon.INVOICESOURCE_OCR, entryTime);

                        invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
                        //生成发票文档
                        ImageDocUtil.updateImageDocId(invoiceData[3]);
                        //插入日志
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = new HashMap<String, String>();
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);
                    } else {
                        //插入日志1
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        rs.executeUpdate("update fnaInvoiceLedger set authenticity=?,checkStatus=? where id=?", AUTHENTICITY_FALSE, checkStatus_3, invoiceData[3]);
                        //插入日志2
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);
                    }
                    jsonObject.put("flag", true);
                    jsonObject.put("checkStatus", "3");
                    jsonObject.put("invoiceNumber", invoiceNumber);
                    jsonObject.put("billingDate", invoiceData[0]);
                    jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                    jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                    jsonObject.put("invoiceId", invoiceData[3]);

                    return jsonObject;
                } else {//更新发票记录

                    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 = Util.getDoubleValue(resultObj.getString("_tax"), 0.00) + "";
                    String _priceWithoutTax = resultObj.getString("_priceWithoutTax");
                    String _invoiceServiceYype = resultObj.getString("_invoiceServiceYype");
                    String _billingDate1 = resultObj.getString("_billingDate");
                    String _taxIncludedPrice = resultObj.getString("_taxIncludedPrice");
                    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");


                    JSONArray detaildata = resultObj.getJSONArray("detaildata");
                    //判断纳税人识别号是否维护
                    boolean protectInvoiceTaxpayerNumber = FnaInvoiceCommon.protectInvoiceTaxpayerNumber(purchaser, _purchaserTaxNo);
                    if (!protectInvoiceTaxpayerNumber) {
                        if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                            String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
                                    + "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,imageID,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                            rs.executeUpdate(insertInvoice, _billingDate1, invoiceCode, invoiceNumber, invoiceType, seller, _salesTaxNo, purchaser, _purchaserTaxNo,
                                    _invoiceServiceYype, _priceWithoutTax, taxRate, tax, df.format(Util.getDoubleValue(_taxIncludedPrice, 0.00)), AUTHENTICITY_UNDETERMINED, checkStatus_3, user.getUID(), imageId, FnaInvoiceCommon.INIT_STATUS, FnaInvoiceCommon.INVOICESOURCE_OCR, entryTime);
                            invoiceData = getInvoiceData(invoiceNumber, invoiceCode);
                            InvoiceUtil.saveVATInvoiceDetail(detaildata, invoiceData[3]);


                            //保存FnaInvoiceLedgerDtl表信息
                            InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0, Util.getIntValue(invoiceData[3], 0), remark, "", sellerAddress, purchaserAddress, salesBank, purchaserBank);
                             //生成发票文档
                            ImageDocUtil.updateImageDocId(invoiceData[3]);
                            //插入日志
                            Map<String, String> labelIdMap = new HashMap<String, String>();
                            Map<String, String> beforeMap = new HashMap<String, String>();
                            Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                            fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                                    beforeMap,afterMap,labelIdMap);
                        } else {

                            //插入日志1
                            Map<String, String> labelIdMap = new HashMap<String, String>();
                            Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);

                            rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=?,checkStatus=?,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?," +
                                            "salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
                                    , tax, _taxIncludedPrice, _billingDate1, purchaser, seller, AUTHENTICITY_UNDETERMINED, checkStatus_3, taxRate, _priceWithoutTax, _invoiceServiceYype,
                                    _salesTaxNo, _purchaserTaxNo, invoiceNumber, invoiceCode);

                            InvoiceUtil.saveVATInvoiceDetail(detaildata, invoiceData[3]);
                            //保存FnaInvoiceLedgerDtl表信息
                            InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1, Util.getIntValue(invoiceData[3], 0), remark, "", sellerAddress, purchaserAddress, salesBank, purchaserBank);

                            //插入日志2
                            Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                            fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
                                    beforeMap,afterMap,labelIdMap);
                        }

                        jsonObject.put("flag", true);
                        jsonObject.put("checkStatus", "3");
                        jsonObject.put("invoiceNumber", invoiceNumber);
                        jsonObject.put("billingDate", invoiceData[0]);
                        jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                        jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                        jsonObject.put("invoiceId", invoiceData[3]);

                        return jsonObject;
                    }
                    if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                        String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
                                + "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,imageID,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        rs.executeUpdate(insertInvoice, _billingDate1, invoiceCode, invoiceNumber, invoiceType, seller, _salesTaxNo, purchaser, _purchaserTaxNo,
                                _invoiceServiceYype, _priceWithoutTax, taxRate, tax, df.format(Util.getDoubleValue(_taxIncludedPrice, 0.00)), AUTHENTICITY_TRUE, checkStatus_1, user.getUID(), imageId, FnaInvoiceCommon.INIT_STATUS, FnaInvoiceCommon.INVOICESOURCE_OCR, entryTime);
                        invoiceData = getInvoiceData(invoiceNumber, invoiceCode);
                        InvoiceUtil.saveVATInvoiceDetail(detaildata, invoiceData[3]);
                        //保存FnaInvoiceLedgerDtl表信息
                        InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0, Util.getIntValue(invoiceData[3], 0), remark, "", sellerAddress, purchaserAddress, salesBank, purchaserBank);

                        //生成发票文档
                        ImageDocUtil.updateImageDocId(invoiceData[3]);
                        //插入日志
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = new HashMap<String, String>();
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);

                    } else {
                        //插入日志1
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);

                        rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=1,checkStatus=1,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?," +
                                        "salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
                                , tax, _taxIncludedPrice, _billingDate1, purchaser, seller, taxRate, _priceWithoutTax, _invoiceServiceYype,
                                _salesTaxNo, _purchaserTaxNo, invoiceNumber, invoiceCode);
                        rs.executeUpdate("delete from FnaInvoiceLedgerDetail where mainid=?", invoiceData[3]);
                        InvoiceUtil.saveVATInvoiceDetail(detaildata, invoiceData[3]);

                        //保存FnaInvoiceLedgerDtl表信息
                        InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1, Util.getIntValue(invoiceData[3], 0), remark, "", sellerAddress, purchaserAddress, salesBank, purchaserBank);
                        //插入日志2
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);
                    }

                    jsonObject.put("flag", true);
                    jsonObject.put("checkStatus", "1");
                    jsonObject.put("invoiceNumber", invoiceNumber);
                    jsonObject.put("billingDate", invoiceData[0]);
                    jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                    jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                    jsonObject.put("invoiceId", invoiceData[3]);

                    return jsonObject;
                }
            }
         }else if("10107".equals(invoiceType)||"10108".equals(invoiceType)){ //增值税专用发票(全电票)
            String VAT_ELEC_GENE_TYPE="";
            if("10107".equals(invoiceType)){
                VAT_ELEC_GENE_TYPE=VAT_ELEC_TYPE;
            }else{
                VAT_ELEC_GENE_TYPE=VAT_GENE_TYPE;
            }
            // String checkCode = Util.null2String(fu.getParameter("check_code"));
            // if(checkCode.length() != 20){
            //      checkCode = "";
            //  }
            String checkCodeSix = "";
            if(checkCode.length()>6){
                checkCodeSix = checkCode.substring(checkCode.length()-6);
            }
            if ("".equals(invoiceNumber)  || "".equals(billingDate) || "".equals(priceWithoutTax)) {
                if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                    if("".equals(priceWithoutTax)){
                        priceWithoutTax = "0.00";
                    }
                    if("".equals(taxIncludedPrice)){
                        taxIncludedPrice = "0.00";
                    }
                    //    if(!"".equals(billingDate_bak) && !checkDate(billingDate)){
                    //       billingDate = getDate();
                    //   }
                    invoiceCode=invoiceNumber;
                    String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
                            " tax,taxIncludedPrice,authenticity,checkStatus,checkcode,userid_new,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                    rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,VAT_ELEC_GENE_TYPE,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
                            0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,0,checkCode,
                            user.getUID(),FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);


                    invoiceData = getInvoiceData(invoiceNumber,invoiceCode);

                }
                jsonObject.put("flag", true);
                jsonObject.put("checkStatus", "0");
                jsonObject.put("invoiceNumber", invoiceNumber);
                jsonObject.put("billingDate", invoiceData[0]);
                jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                jsonObject.put("invoiceId", invoiceData[3]);
                //生成发票文档
                ImageDocUtil.updateImageDocId(invoiceData[3]);
                return jsonObject;
            }else{
                invoiceCode=invoiceNumber;
                String result = "01,10," + invoiceCode + "," + invoiceNumber
                        + "," + df.format(Util.getDoubleValue(taxIncludedPrice,0.00)) + ","
                        + billingDate.replaceAll("-", "") + ","
                        + "" + ",1111,";
                  new BaseBean().writeLog("invoiceCheck-result:", result);
                FnaAbstractInterface fnaAbstractInterface = new FnaInvoiceCommon().getInterface(user);
                JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result,null);
                new BaseBean().writeLog("1111111111111");
                int checkstatus = resultObj.getInt("status");
                if (checkstatus == 0) { //验票失败
                    if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                        String selectSql="select  count(*) from fnaInvoiceLedger where invoiceCode=? and invoiceNumber=?";
                        rs.executeQuery(selectSql,invoiceCode,invoiceNumber);
                        int colCounts = rs.getColCounts();

                        String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
                                " tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,checkCode,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,VAT_ELEC_GENE_TYPE,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
                                0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_FALSE,3,
                                user.getUID(),FnaInvoiceCommon.INIT_STATUS,checkCode,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);


                        //生成发票文档
                        ImageDocUtil.updateImageDocId(invoiceData[3]);
                        invoiceData = getInvoiceData(invoiceNumber,invoiceCode);

                    }
                    jsonObject.put("flag", true);
                    jsonObject.put("checkStatus", "3");
                    jsonObject.put("invoiceNumber", invoiceNumber);
                    jsonObject.put("billingDate", invoiceData[0]);
                    jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                    jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                    jsonObject.put("invoiceId", invoiceData[3]);
                    //生成发票文档
                    return jsonObject;
                }else{//更新发票记录
                    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 remark = resultObj.getString("_remark");
                    String sellerAddress = resultObj.getString("_sellerAddress");
                    String purchaserAddress = resultObj.getString("_purchaserAddress");
                    String salesBank = resultObj.getString("_salesBank");
                    String purchaserBank = resultObj.getString("_purchaserBank");
                    JSONArray detaildata = resultObj.getJSONArray("detaildata");
                    invoiceCode=invoiceNumber;
                    //判断纳税人识别号是否维护
                    boolean protectInvoiceTaxpayerNumber = FnaInvoiceCommon.protectInvoiceTaxpayerNumber(purchaser,_purchaserTaxNo);
                    if(!protectInvoiceTaxpayerNumber){
                        if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {

                            String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
                                    + "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,checkCode,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                            rs.executeUpdate(insertInvoice,_billingDate1,invoiceCode,invoiceNumber,VAT_ELEC_GENE_TYPE,seller,_salesTaxNo,purchaser,_purchaserTaxNo,
                                    _invoiceServiceYype,_priceWithoutTax,taxRate,tax,df.format(Util.getDoubleValue(_taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,3,user.getUID(),checkCode,FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
                            invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
                            InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
                            //保存FnaInvoiceLedgerDtl表信息
                            //生成发票文档
                            ImageDocUtil.updateImageDocId(invoiceData[3]);
                            InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);




                        }else{
                            rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=?,checkStatus=?,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
                                            "checkCode=?,salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
                                    ,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,AUTHENTICITY_UNDETERMINED,3,taxRate,_priceWithoutTax,_invoiceServiceYype,checkCode,
                                    _salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);

                            InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
                            //保存FnaInvoiceLedgerDtl表信息
                            InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);



                        }
                        jsonObject.put("flag", true);
                        jsonObject.put("checkStatus", "3");
                        jsonObject.put("invoiceNumber", invoiceNumber);
                        jsonObject.put("billingDate", invoiceData[0]);
                        jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                        jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                        jsonObject.put("invoiceId", invoiceData[3]);
                        return jsonObject;
                    }

                    if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                        String selectSql="select  count(*) from fnaInvoiceLedger where invoiceCode=? and invoiceNumber=?";
                        rs.executeQuery(selectSql,invoiceCode,invoiceNumber);
                        int colCounts = rs.getColCounts();
                        if(colCounts>0){
                            rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=1,checkStatus=1,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
                                            "checkCode=?,salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
                                    ,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,taxRate,_priceWithoutTax,_invoiceServiceYype,checkCode,
                                    _salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);
                            rs.executeUpdate("delete from FnaInvoiceLedgerDetail where mainid=?",invoiceData[3]);
                        }else{
                            String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
                                    + "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,checkCode,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                            rs.executeUpdate(insertInvoice,_billingDate1,invoiceCode,invoiceNumber,VAT_ELEC_GENE_TYPE,seller,_salesTaxNo,purchaser,_purchaserTaxNo,
                                    _invoiceServiceYype,_priceWithoutTax,taxRate,tax,df.format(Util.getDoubleValue(_taxIncludedPrice,0.00)),AUTHENTICITY_TRUE,1,user.getUID(),checkCode,FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);

                        }
                        invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
                        InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
                        //生成发票文档
                        ImageDocUtil.updateImageDocId(invoiceData[3]);
                        //保存FnaInvoiceLedgerDtl表信息
                        InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);



                    }else{


                        rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=1,checkStatus=1,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
                                        "checkCode=?,salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
                                ,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,taxRate,_priceWithoutTax,_invoiceServiceYype,checkCode,
                                _salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);
                        rs.executeUpdate("delete from FnaInvoiceLedgerDetail where mainid=?",invoiceData[3]);
                        //保存FnaInvoiceLedgerDtl表信息
                        InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
                        InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);


                    }
                    jsonObject.put("flag", true);
                    jsonObject.put("checkStatus", "1");
                    jsonObject.put("invoiceNumber", invoiceNumber);
                    jsonObject.put("billingDate", invoiceData[0]);
                    jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                    jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                    jsonObject.put("invoiceId", invoiceData[3]);
                    return jsonObject;
                }
            }
        }else if("10101".equals(invoiceType) || "10102".equals(invoiceType) || "10103".equals(invoiceType) || "20".equals(invoiceType)){
            String invoiceTypeTrue="";
            if("10101".equals(invoiceType)){
                invoiceTypeTrue = VAT_ORDINARY_TYPE;
            }else if("10102".equals(invoiceType)){
                invoiceTypeTrue = VAT_Electronic_Type;
            }else if("10103".equals(invoiceType)){
                invoiceTypeTrue = VAT_ORDINARY_Volume_TYPE;
            }else if("20".equals(invoiceType)){
                invoiceTypeTrue = VAT_Electronic_Tolls_Type;
            }

            String checkCodeSix = "";
            if(checkCode.length()>6){
                checkCodeSix = checkCode.substring(checkCode.length()-6);
            }
            if ("".equals(invoiceNumber) || "".equals(invoiceCode) || "".equals(billingDate) || "".equals(checkCode)) {
                if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                    if("".equals(priceWithoutTax)){
                        priceWithoutTax = "0.00";
                    }
                    if("".equals(taxIncludedPrice)){
                        taxIncludedPrice = "0.00";
                    }

                    String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
                            " tax,taxIncludedPrice,authenticity,checkStatus,checkcode,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                    rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,invoiceTypeTrue,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
                            0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,checkStatus_0,checkCode,
                            user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageId,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);

                    invoiceData = getInvoiceData(invoiceNumber,invoiceCode);

                    //生成发票文档
                    ImageDocUtil.updateImageDocId(invoiceData[3]);
                    //插入日志
                    Map<String, String> labelIdMap = new HashMap<String, String>();
                    Map<String, String> beforeMap = new HashMap<String, String>();
                    Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                    fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                            beforeMap,afterMap,labelIdMap);
                }

                jsonObject.put("flag", true);
                jsonObject.put("checkStatus", "0");
                jsonObject.put("invoiceNumber", invoiceNumber);
                jsonObject.put("billingDate", invoiceData[0]);
                jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                jsonObject.put("invoiceId", invoiceData[3]);

                return jsonObject;
            }else{
                String result = "01,10," + invoiceCode + "," + invoiceNumber
                        + "," + priceWithoutTax + ","
                        + billingDate.replaceAll("-", "") + ","
                        + checkCode.replace(checkCode.substring(0,14),"00000000000000") + ",1111,";
                FnaAbstractInterface fnaAbstractInterface = new FnaInvoiceCommon().getInterface(user);
                JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result,null);
                int checkstatus = resultObj.getInt("status");
                if (checkstatus == 0) {//验票失败
                    if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                        String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
                                " tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,checkCode,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,invoiceTypeTrue,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
                                0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_FALSE,checkStatus_3,
                                user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageId,checkCode,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);

                        invoiceData = getInvoiceData(invoiceNumber,invoiceCode);

                        //生成发票文档
                        ImageDocUtil.updateImageDocId(invoiceData[3]);
                        //插入日志
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = new HashMap<String, String>();
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);
                    }else{
                        //插入日志1
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        rs.executeUpdate("update fnaInvoiceLedger set authenticity=?,checkStatus=? where id=?",AUTHENTICITY_FALSE,checkStatus_3,invoiceData[3]);
                        //插入日志2
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);
                    }

                    jsonObject.put("flag", true);
                    jsonObject.put("checkStatus", "3");
                    jsonObject.put("invoiceNumber", invoiceNumber);
                    jsonObject.put("billingDate", invoiceData[0]);
                    jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                    jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                    jsonObject.put("invoiceId", invoiceData[3]);
                    return jsonObject;
                }else{//更新发票记录
                    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 = Util.getDoubleValue(resultObj.getString("_tax"),0.00)+"";
                    String _priceWithoutTax = resultObj.getString("_priceWithoutTax");
                    String _invoiceServiceYype = resultObj.getString("_invoiceServiceYype");
                    String _billingDate1 = resultObj.getString("_billingDate");
                    String _taxIncludedPrice = resultObj.getString("_taxIncludedPrice");
                    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");
                    JSONArray detaildata = resultObj.getJSONArray("detaildata");
                    //判断纳税人识别号是否维护
                    boolean protectInvoiceTaxpayerNumber = FnaInvoiceCommon.protectInvoiceTaxpayerNumber(purchaser,_purchaserTaxNo);
                    if(!protectInvoiceTaxpayerNumber){
                        if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                            String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
                                    + "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,imageID,checkCode,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                            rs.executeUpdate(insertInvoice,_billingDate1,invoiceCode,invoiceNumber,invoiceTypeTrue,seller,_salesTaxNo,purchaser,_purchaserTaxNo,
                                    _invoiceServiceYype,_priceWithoutTax,taxRate,tax,df.format(Util.getDoubleValue(_taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,checkStatus_3,user.getUID(),imageId,checkCode,FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
                            invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
                            InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);


                            //保存FnaInvoiceLedgerDtl表信息
                            InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);

                            //生成发票文档
                            ImageDocUtil.updateImageDocId(invoiceData[3]);
                            //插入日志
                            Map<String, String> labelIdMap = new HashMap<String, String>();
                            Map<String, String> beforeMap = new HashMap<String, String>();
                            Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                            fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                                    beforeMap,afterMap,labelIdMap);
                        }else{

                            //插入日志1
                            Map<String, String> labelIdMap = new HashMap<String, String>();
                            Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);

                            rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=?,checkStatus=?,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
                                            "checkCode=?,salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
                                    ,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,AUTHENTICITY_UNDETERMINED,checkStatus_3,taxRate,_priceWithoutTax,_invoiceServiceYype,checkCode,
                                    _salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);

                            InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
                            //保存FnaInvoiceLedgerDtl表信息
                            InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);

                            //插入日志2
                            Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                            fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
                                    beforeMap,afterMap,labelIdMap);

                        }
                        jsonObject.put("flag", true);
                        jsonObject.put("checkStatus", "3");
                        jsonObject.put("invoiceNumber", invoiceNumber);
                        jsonObject.put("billingDate", invoiceData[0]);
                        jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                        jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                        jsonObject.put("invoiceId", invoiceData[3]);
                        return jsonObject;
                    }
                    if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                        String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
                                + "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,imageID,checkCode,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        rs.executeUpdate(insertInvoice,_billingDate1,invoiceCode,invoiceNumber,invoiceTypeTrue,seller,_salesTaxNo,purchaser,_purchaserTaxNo,
                                _invoiceServiceYype,_priceWithoutTax,taxRate,tax,df.format(Util.getDoubleValue(_taxIncludedPrice,0.00)),AUTHENTICITY_TRUE,checkStatus_1,user.getUID(),imageId,checkCode,FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
                        invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
                        InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);


                        //保存FnaInvoiceLedgerDtl表信息
                        InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);

                        //生成发票文档
                        ImageDocUtil.updateImageDocId(invoiceData[3]);
                        //插入日志
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = new HashMap<String, String>();
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);
                    }else{

                        //插入日志1
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);

                        rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=1,checkStatus=1,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
                                        "checkCode=?,salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
                                ,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,taxRate,_priceWithoutTax,_invoiceServiceYype,checkCode,
                                _salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);
                        rs.executeUpdate("delete from FnaInvoiceLedgerDetail where mainid=?",invoiceData[3]);
                        InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);

                        //保存FnaInvoiceLedgerDtl表信息
                        InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);

                        //保存FnaInvoiceLedgerDtl表信息
                        InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);

                    }
                    jsonObject.put("flag", true);
                    jsonObject.put("checkStatus", "1");
                    jsonObject.put("invoiceNumber", invoiceNumber);
                    jsonObject.put("billingDate", invoiceData[0]);
                    jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                    jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                    jsonObject.put("invoiceId", invoiceData[3]);
                    return jsonObject;
                }
            }
        }else if("10104".equals(invoiceType)){//机动车销售统一发票
            if ("".equals(invoiceNumber) || "".equals(invoiceCode) || "".equals(billingDate) || "".equals(priceWithoutTax)) {
                if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {


                    String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
                            " tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                    rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,MOTORVEHICLESALES_TYPE,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
                            0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,checkStatus_0,
                            user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageId,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);


                    invoiceData = getInvoiceData(invoiceNumber,invoiceCode);

                    //生成发票文档
                    ImageDocUtil.updateImageDocId(invoiceData[3]);
                    //插入日志
                    Map<String, String> labelIdMap = new HashMap<String, String>();
                    Map<String, String> beforeMap = new HashMap<String, String>();
                    Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                    fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                            beforeMap,afterMap,labelIdMap);
                }
                jsonObject.put("flag", true);
                jsonObject.put("checkStatus", "0");
                jsonObject.put("invoiceNumber", invoiceNumber);
                jsonObject.put("billingDate", invoiceData[0]);
                jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                jsonObject.put("invoiceId", invoiceData[3]);
                return jsonObject;
            }else{
                String result = "01,01," + invoiceCode + "," + invoiceNumber
                        + "," + priceWithoutTax
                        + "," + billingDate.replaceAll("-", "")
                        + ",,1111,";
                FnaAbstractInterface fnaAbstractInterface = new FnaInvoiceCommon().getInterface(user);
                JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result,null);
                int checkstatus = resultObj.getInt("status");
                if (checkstatus == 0) {//验票失败
                    if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                        String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
                                " tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,MOTORVEHICLESALES_TYPE,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
                                0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_FALSE,checkStatus_3,
                                user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageId,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);

                        invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
                        //生成发票文档
                        ImageDocUtil.updateImageDocId(invoiceData[3]);
                        //插入日志
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = new HashMap<String, String>();
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);
                    }else{
                        //插入日志1
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        rs.executeUpdate("update fnaInvoiceLedger set authenticity=?,checkStatus=? where id=?",AUTHENTICITY_FALSE,3,invoiceData[3]);
                        //插入日志2
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);
                    }

                    jsonObject.put("flag", true);
                    jsonObject.put("checkStatus", "3");
                    jsonObject.put("invoiceNumber", invoiceNumber);
                    jsonObject.put("billingDate", invoiceData[0]);
                    jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                    jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                    jsonObject.put("invoiceId", invoiceData[3]);
                    return jsonObject;
                }else{//更新发票记录
                    //获取发票信息
                    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");
                    if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
                        String sql="insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,purchaser,salesTaxNo,purchaserTaxNo,"+
                                "invoiceServiceYype,priceWithoutTax,tax,taxRate,taxIncludedPrice,authenticity,checkStatus,"+
                                "userid_new,invoiceSource_new,status,entryTime,imageId)"+
                                "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                        rs.executeUpdate(sql,billingDateTrue,invoicecodeTrue,invoiceNumberTrue,MOTORVEHICLESALES_TYPE,sellerTrue,purchaserTrue,salesTaxNoTrue,purchaserTaxNoTrue,
                                "",priceWithoutTaxTrue,taxTrue,taxRateTrue,taxIncludedPriceTrue,1,1,
                                user.getUID(), FnaInvoiceCommon.INVOICESOURCE_OCR,0,entryTime,imageId);
                        invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
                        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(?,?,?,?,?,?,?,?,?)",
                                invoiceData[3],machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number);

                        //保存FnaInvoiceLedgerDtl表信息
                        InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);


                        //插入明细
                        InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceData[3],0),Constants.INVOICESERVICEYYPE.get(invoiceType),priceWithoutTaxTrue,taxRateTrue,taxTrue,1,priceWithoutTaxTrue,priceWithoutTaxTrue,"","");

                        //生成发票文档
                        ImageDocUtil.updateImageDocId(invoiceData[3]);
                        //插入日志
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = new HashMap<String, String>();
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);
                    }else{

                        //插入日志1
                        Map<String, String> labelIdMap = new HashMap<String, String>();
                        Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);

                        rs.executeUpdate("update fnaInvoiceLedger set billingDate=?,invoiceCode=?,invoiceNumber=?,invoiceType=?,seller=?,purchaser=?,salesTaxNo=?,purchaserTaxNo=?," +
                                        "priceWithoutTax=?,tax=?,taxRate=?,taxIncludedPrice=?,authenticity=?,checkStatus=?,imageId=? where id=?"
                                ,billingDateTrue,invoicecodeTrue,invoiceNumberTrue,MOTORVEHICLESALES_TYPE,sellerTrue,purchaserTrue,salesTaxNoTrue,purchaserTaxNoTrue,
                                priceWithoutTaxTrue,taxTrue,taxRateTrue,taxIncludedPriceTrue,1,1,imageId,invoiceData[3]);
                        rs.executeQuery("select 1 from motor_VehicleInvoice where mainid=?",invoiceData[3]);
                        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,invoiceData[3]);

                        }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(?,?,?,?,?,?,?,?,?)",
                                    invoiceData[3],machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number);

                        }

                        //保存FnaInvoiceLedgerDtl表信息
                        InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);

                        //插入明细
                        InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceData[3],0),Constants.INVOICESERVICEYYPE.get(invoiceType),priceWithoutTaxTrue,taxRateTrue,taxTrue,1,priceWithoutTaxTrue,priceWithoutTaxTrue,"","");

                        //插入日志2
                        Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
                                beforeMap,afterMap,labelIdMap);
                    }
                    jsonObject.put("flag", true);
                    jsonObject.put("checkStatus", "1");
                    jsonObject.put("invoiceNumber", invoiceNumber);
                    jsonObject.put("billingDate", invoiceData[0]);
                    jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
                    jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice, 0.00)));
                    jsonObject.put("invoiceId", invoiceData[3]);
                    return jsonObject;
                }
            }
        }

        return null;
    }

    /**
     * 展示发票信息页面
     * @param params
     * @param user
     * @return
     * @throws Exception 
     */
    public Map<String,Object> invoiceShow(Map<String,Object> params, User user) throws Exception{
        Map<String, Object> result = new HashMap<String, Object>();
        List<Map<String, Object>> grouplist = new LinkedList<Map<String, Object>>();
        ConditionFactory conditionFactory = new ConditionFactory(user);
        //基本信息
        Map<String, Object> groupitem = new HashMap<String, Object>();
        List<SearchConditionItem> itemlist = new LinkedList<SearchConditionItem>();

        String invoiceId = Util.null2String(params.get("invoiceId"));
        
        checkInvoiceBelongs(user, invoiceId);
        
        String invoiceType="";
        RecordSet rs = new RecordSet();
        RecordSet rs2 = new RecordSet();
        rs.executeQuery("select * from fnaInvoiceLedger where id=?",invoiceId);
        if(rs.next()){
            invoiceType = Util.null2String(rs.getString("invoiceType"));
            int checkStatus = Util.getIntValue(rs.getString("checkStatus"),0);
            double totalAmount= Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00);
            boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
            boolean existInterface = InvoiceUtil.ifExistsInterface(user);
            //发票类型
            SearchConditionItem invoiceTypeItem = conditionFactory.createCondition(ConditionType.INPUT, 131489, "invoiceType");
            invoiceTypeItem.setViewAttr(1);
            invoiceTypeItem.setValue(Constants.INVOICETYPE.get(invoiceType));
            itemlist.add(invoiceTypeItem);

            boolean showSave=false;
            boolean showCheck=false;
            boolean showDelete=true;
            if(VAT_ORDINARY_TYPE.equals(invoiceType) || VAT_SPECIAL_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_ELEC_TYPE.equals(invoiceType)) {//增值税发票
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String priceWithoutTax = df.format(Util.getDoubleValue(rs.getString("priceWithoutTax"),0.00));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String seller = Util.null2String(rs.getString("seller"));
                String purchaser = Util.null2String(rs.getString("purchaser"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String checkCode = Util.null2String(rs.getString("checkCode"));
                String salesTaxNo = Util.null2String(rs.getString("salesTaxNo"));
                String purchaserTaxNo = Util.null2String(rs.getString("purchaserTaxNo"));
                if(checkStatus == checkStatus_1){//有效已查验
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",1,invoiceCode,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",1,invoiceNumber,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",1,taxIncludedPrice,2);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,514098,"priceWithoutTax",1,priceWithoutTax,2);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",1,billingDate,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131490,"seller",1,seller,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131491,"purchaser",1,purchaser,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,"131490,389934","salesTaxNo",1,salesTaxNo,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,"131491,389934","purchaserTaxNo",1,purchaserTaxNo,0);
                }else if(checkStatus == checkStatus_2 || ((checkStatus == checkStatus_0 ||  checkStatus == checkStatus_3)&& !(existInterface && needCheck))){//有效未查验
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,514098,"priceWithoutTax",3,priceWithoutTax,2);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131490,"seller",2,seller,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131491,"purchaser",2,purchaser,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,"131490,389934","salesTaxNo",2,salesTaxNo,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,"131491,389934","purchaserTaxNo",2,purchaserTaxNo,0);
                    String category = Util.null2String(rs.getString("category"));//种类
                    String kind = Util.null2String(rs.getString("kind"));//发票消费类型
                    if(VAT_ORDINARY_TYPE.equals(invoiceType) || VAT_Electronic_Type.equals(invoiceType) || VAT_ORDINARY_Volume_TYPE.equals(invoiceType) || VAT_Electronic_Tolls_Type.equals(invoiceType) ){//如果是增值税普通发票
                        this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,382639,"checkCode",2,checkCode,0);
                        this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,716,"category",2,category,0);
                        this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);
                    }else{//增值税专用发票

                        String tax = df.format(Util.getDoubleValue(rs.getString("tax"),0.00));
                        String taxRate = Util.null2String(rs.getString("taxRate"));
                        int company_seal = Util.getIntValue(rs.getString("company_seal"),0);//是否有公司印章
                        String form_type = Util.null2String(rs.getString("form_type"));//发票是第几联
                        String form_name = Util.null2String(rs.getString("form_name"));//发票联次

                        this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131495,"tax",2,tax,2);
                        this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,391179,"taxRate",2,taxRate,2);

                        //是否有公司印章
                        List<SearchConditionOption> company_sealOptions = new ArrayList<SearchConditionOption>();
                        company_sealOptions.add(new SearchConditionOption(0+"", SystemEnv.getHtmlLabelName(26161,user.getLanguage()),company_seal==0?true:false));
                        company_sealOptions.add(new SearchConditionOption(1+"", SystemEnv.getHtmlLabelName(15086,user.getLanguage()),company_seal==1?true:false));
                        SearchConditionItem company_sealItem = conditionFactory.createCondition(ConditionType.SELECT, 505721, "company_seal", company_sealOptions);//发票类型
                        itemlist.add(company_sealItem);

                        this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505722,"form_type",2,form_type,0);
                        this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505723,"form_name",2,form_name,0);
                        this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);
                    }
                    showSave=true;
                }else if(checkStatus == checkStatus_0 ||  checkStatus == checkStatus_3){
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,514098,"priceWithoutTax",3,priceWithoutTax,2);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,382639,"checkCode",3,checkCode,0);
                    showCheck=true;

                }
            }else if(MOTORVEHICLESALES_TYPE.equals(invoiceType)) {//机动车销售统一发票
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String priceWithoutTax = df.format(Util.getDoubleValue(rs.getString("priceWithoutTax"),0.00));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String seller = Util.null2String(rs.getString("seller"));
                String purchaser = Util.null2String(rs.getString("purchaser"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                if(checkStatus == checkStatus_1){
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",1,invoiceCode,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",1,invoiceNumber,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",1,taxIncludedPrice,2);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,514098,"priceWithoutTax",1,priceWithoutTax,2);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",1,billingDate,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131490,"seller",1,seller,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131491,"purchaser",1,purchaser,0);
                }else if(checkStatus == checkStatus_2 || ((checkStatus == checkStatus_0 ||  checkStatus == checkStatus_3)&& !(existInterface && needCheck))){//有效未查验
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,514098,"priceWithoutTax",3,priceWithoutTax,2);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131490,"seller",3,seller,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131491,"purchaser",3,purchaser,0);
                    showSave=true;
                }else{
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                    this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,514098,"priceWithoutTax",3,priceWithoutTax,2);
                    showCheck=true;
                }
            }else if(USEDCARSALES_TYPE.equals(invoiceType)) {//二手车销售统一发票
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String seller_id="";//卖方单位代码/个人身份证号
                String buyer_id="";//买方单位代码/个人身份证号
                String company_name="";//二手车市场
                String company_tax_id="";//二手车市场纳税人识别号
                String license_plate="";//车牌号
                String registration_number="";//登记证号
                String car_code="";//车架号/车辆识别代码
                String car_model="";//厂牌型号
                rs2.executeQuery("select * from second_carInvoice where mainid = ?",invoiceId);
                if(rs2.next()){
                    seller_id = Util.null2String(rs2.getString("seller_id"));
                    buyer_id = Util.null2String(rs2.getString("buyer_id"));
                    company_name = Util.null2String(rs2.getString("company_name"));
                    company_tax_id = Util.null2String(rs2.getString("company_tax_id"));
                    license_plate = Util.null2String(rs2.getString("license_plate"));
                    registration_number = Util.null2String(rs2.getString("registration_number"));
                    car_code = Util.null2String(rs2.getString("car_code"));
                    car_model = Util.null2String(rs2.getString("car_model"));
                }

                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);

                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509625,"seller_id",2,seller_id,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509626,"buyer_id",2,buyer_id,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509627,"company_name",2,company_name,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509628,"company_tax_id",2,company_tax_id,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509629,"license_plate",2,license_plate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509630,"registration_number",2,registration_number,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509631,"car_code",2,car_code,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509632,"car_model",2,car_model,0);
                showSave=true;
            }else if(QUOTA_TYPE.equals(invoiceType)) {//定额发票
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String kind = Util.null2String(rs.getString("kind"));//发票消费类型
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);
                showSave=true;
            }else if(GENERALMACHINE_TYPE.equals(invoiceType)) {//机打发票
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String seller = Util.null2String(rs.getString("seller"));
                String purchaser = Util.null2String(rs.getString("purchaser"));
                String checkCode = Util.null2String(rs.getString("checkCode"));
                String kind = Util.null2String(rs.getString("kind"));
                String time="";//时间
                String category="";//种类，oil 表示是加油票
                String salesTaxNo=Util.null2String(rs.getString("salesTaxNo"));// 销售方纳税人识别号
                String purchaserTaxNo=Util.null2String(rs.getString("purchaserTaxNo"));//购买方纳税人识别号
                rs2.executeQuery("select * from machineInvoice where mainid = ?",invoiceId);
                if(rs2.next()){
                    time = Util.null2String(rs2.getString("time"));
                    category = Util.null2String(rs2.getString("category"));
                }


                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131490,"seller",2,seller,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131491,"purchaser",2,purchaser,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,382639,"checkCode",2,checkCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.TIMEPICKER,19736,"time",2,time,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,716,"category",2,category,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,501163,"salesTaxNo",2,salesTaxNo,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,501164,"purchaserTaxNo",2,purchaserTaxNo,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);

                String sellerAddress="";
                String purchaserAddress="";
                String salesBank="";
                String purchaserBank="";
                rs2.executeQuery("select * from FnaInvoiceLedgerDtl where mainid = ?",invoiceId);
                if(rs2.next()){
                    sellerAddress = Util.null2String(rs2.getString("sellerAddress"));
                    purchaserAddress = Util.null2String(rs2.getString("purchaserAddress"));
                    salesBank = Util.null2String(rs2.getString("salesBank"));
                    purchaserBank = Util.null2String(rs2.getString("purchaserBank"));
                }
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529910,"sellerAddress",2,sellerAddress,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529911,"purchaserAddress",2,purchaserAddress,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529912,"salesBank",2,salesBank,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529913,"purchaserBank",2,purchaserBank,0);


                showSave=true;
            }else if(TAXI_TYPE.equals(invoiceType)) {//出租车发票
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String kind = Util.null2String(rs.getString("kind"));
                String time_geton="";//上车时间
                String time_getoff="";//下车时间
                String mileage="";//里程
                String place="";//发票所在地
                rs2.executeQuery("select * from taxiInvoice where mainid = ?",invoiceId);
                if(rs2.next()){
                    time_geton = Util.null2String(rs2.getString("time_geton"));
                    time_getoff = Util.null2String(rs2.getString("time_getoff"));
                    mileage = Util.null2String(rs2.getString("mileage"));
                    place = Util.null2String(rs2.getString("place"));
                }
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);

                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.TIMEPICKER,505751,"time_geton",2,time_geton,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.TIMEPICKER,505752,"time_getoff",2,time_getoff,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,19055,"mileage",2,mileage,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,"132211,131722","place",2,place,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);
                showSave=true;
            }else if(TRAIN_TYPE.equals(invoiceType)) {//火车票
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String kind = Util.null2String(rs.getString("kind"));
                String time="";//时间
                String name="";//乘车人姓名
                String station_geton="";//上车车站
                String station_getoff="";//下车车站
                String train_number="";//车次
                String seat="";//座位类型
                rs2.executeQuery("select * from trainInvoice where mainid = ?",invoiceId);
                if(rs2.next()){
                    time = Util.null2String(rs2.getString("time"));
                    name = Util.null2String(rs2.getString("name"));
                    station_geton = Util.null2String(rs2.getString("station_geton"));
                    station_getoff = Util.null2String(rs2.getString("station_getoff"));
                    train_number = Util.null2String(rs2.getString("train_number"));
                    seat = Util.null2String(rs2.getString("seat"));
                }
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);

                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.TIMEPICKER,19736,"time",2,time,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,413,"name",2,name,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505760,"station_geton",2,station_geton,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505761,"station_getoff",2,station_getoff,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505780,"train_number",2,train_number,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505781,"seat",2,seat,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);
                showSave=true;
            }else if(PASSENGERTICKET_TYPE.equals(invoiceType)) {//客运汽车
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String kind = Util.null2String(rs.getString("kind"));
                String time="";//时间
                String station_geton="";//上车车站
                String station_getoff="";//下车车站
                String name="";//乘车人姓名
                rs2.executeQuery("select * from carInvoice where mainid = ?",invoiceId);
                if(rs2.next()){
                    time = Util.null2String(rs2.getString("time"));
                    name = Util.null2String(rs2.getString("name"));
                    station_geton = Util.null2String(rs2.getString("station_geton"));
                    station_getoff = Util.null2String(rs2.getString("station_getoff"));
                }
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.TIMEPICKER,19736,"time",2,time,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,413,"name",2,name,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505760,"station_geton",2,station_geton,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505761,"station_getoff",2,station_getoff,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);
                showSave=true;
            }else if(AIRTRANSPORTTICKET_TYPE.equals(invoiceType)) {//航空运输电子客票行程单
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String kind = Util.null2String(rs.getString("kind"));
                String user_name="";// 乘机人姓名
                String user_id="";//身份证号
                String agentcode="";//销售单位代号
                String issue_by="";//填开单位
                String fare="";//票价
                String fuel_surcharge="";//燃油附加费
                String caac_development_fund="";//民航发展基金
                String insurance="";//保险费
                rs2.executeQuery("select * from airInvoice where mainid = ?",invoiceId);
                if(rs2.next()){
                    user_name = Util.null2String(rs2.getString("user_name"));
                    user_id = Util.null2String(rs2.getString("user_id"));
                    agentcode = Util.null2String(rs2.getString("agentcode"));
                    issue_by = Util.null2String(rs2.getString("issue_by"));
                    fare = df.format(Util.getDoubleValue(rs2.getString("fare"),0.00));
                    fuel_surcharge = df.format(Util.getDoubleValue(rs2.getString("fuel_surcharge"),0.00));
                    caac_development_fund = df.format(Util.getDoubleValue(rs2.getString("caac_development_fund"),0.00));
                    insurance = df.format(Util.getDoubleValue(rs2.getString("insurance"),0.00));
                }

                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);

                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505910,"user_name",2,user_name,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505911,"user_id",2,user_id,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505912,"agentcode",2,agentcode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505913,"issue_by",2,issue_by,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,505914,"fare",2,fare,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,505915,"fuel_surcharge",2,fuel_surcharge,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,505916,"caac_development_fund",2,caac_development_fund,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,23406,"insurance",2,insurance,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);
                showSave=true;
            }else if(TOLLS_TYPE.equals(invoiceType)) {//过路费发票
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String kind = Util.null2String(rs.getString("kind"));
                String time="";//时间
                String entrance="";//入口
                String exit="";//出口
                rs2.executeQuery("select * from tollInvoice where mainid = ?",invoiceId);
                if(rs2.next()){
                    time = Util.null2String(rs2.getString("time"));
                    entrance = Util.null2String(rs2.getString("entrance"));
                    exit = Util.null2String(rs2.getString("export"));
                }
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.TIMEPICKER,19736,"time",2,time,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,126473,"entrance",2,entrance,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,15587,"exit",2,exit,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);
                showSave=true;
            }else if(INTERNATIONAL_RECEIPTS.equals(invoiceType)) {//国际小票
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String priceWithoutTax = df.format(Util.getDoubleValue(rs.getString("priceWithoutTax"),0.00));
                String tax = df.format(Util.getDoubleValue(rs.getString("tax"),0.00));
                String storename = "";
                String time = "";
                String discount = "";
                String tips = "";
                String currency_code = "";
                String xftype = "";
                rs2.executeQuery("select * from smallInvoice where mainid = ?",invoiceId);
                while(rs2.next()){
                    storename = Util.null2String(rs2.getString("storename"));
                    time = Util.null2String(rs2.getString("time"));
                    discount = Util.null2String(rs2.getString("discount"));
                    tips = Util.null2String(rs2.getString("tips"));
                    currency_code = Util.null2String(rs2.getString("currency_code"));
                    xftype = Util.null2String(rs2.getString("type"));
                }
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,514098,"priceWithoutTax",2,priceWithoutTax,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131495,"tax",2,tax,2);


                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509634,"storename",2,storename,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.TIMEPICKER,19736,"time",2,time,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509636,"discount",2,discount,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509637,"tips",2,tips,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509638,"currency_code",2,currency_code,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,509639,"xftype",2,xftype,0);
                showSave=true;
            }else if(OTHERS_TYPE.equals(invoiceType)) {//可报销的其他发票
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String kind = Util.null2String(rs.getString("kind"));
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);

                String seller = Util.null2String(rs.getString("seller"));
                String purchaser = Util.null2String(rs.getString("purchaser"));
                String salesTaxNo = Util.null2String(rs.getString("salesTaxNo"));
                String purchaserTaxNo = Util.null2String(rs.getString("purchaserTaxNo"));
                String sellerAddress="";
                String purchaserAddress="";
                String salesBank="";
                String purchaserBank="";
                rs2.executeQuery("select * from FnaInvoiceLedgerDtl where mainid = ?",invoiceId);
                if(rs2.next()){
                    sellerAddress = Util.null2String(rs2.getString("sellerAddress"));
                    purchaserAddress = Util.null2String(rs2.getString("purchaserAddress"));
                    salesBank = Util.null2String(rs2.getString("salesBank"));
                    purchaserBank = Util.null2String(rs2.getString("purchaserBank"));
                }
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,10003289,"seller",2,seller,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,10003290,"purchaser",2,purchaser,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,10003291,"salesTaxNo",2,salesTaxNo,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,10003292,"purchaserTaxNo",2,purchaserTaxNo,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529910,"sellerAddress",2,sellerAddress,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529911,"purchaserAddress",2,purchaserAddress,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529912,"salesBank",2,salesBank,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529913,"purchaserBank",2,purchaserBank,0);


                showSave=true;
            }else if(TAX_CERTIFICATE_TYPE.equals(invoiceType)) {//完税证明
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String purchaser = Util.null2String(rs.getString("purchaser"));
                String purchaserTaxNo = Util.null2String(rs.getString("purchaserTaxNo"));
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131491,"purchaser",2,purchaser,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,"131491,389934","purchaserTaxNo",2,purchaserTaxNo,0);
                showSave=true;
            }else if(BLOCKCHAIN_TYPE.equals(invoiceType)) {//完税证明
                String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
                String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
                String billingDate = Util.null2String(rs.getString("billingDate"));
                String taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
                String priceWithoutTax = df.format(Util.getDoubleValue(rs.getString("priceWithoutTax"),0.00));

                String checkCode = Util.null2String(rs.getString("checkCode"));
                String seller = Util.null2String(rs.getString("seller"));
                String purchaser = Util.null2String(rs.getString("purchaser"));
                String salesTaxNo = Util.null2String(rs.getString("salesTaxNo"));
                String purchaserTaxNo = Util.null2String(rs.getString("purchaserTaxNo"));
                String kind = Util.null2String(rs.getString("kind"));
                String category = Util.null2String(rs.getString("category"));

                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131487,"invoiceCode",3,invoiceCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131488,"invoiceNumber",3,invoiceNumber,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.DATEPICKER,131486,"billingDate",3,billingDate,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,131496,"taxIncludedPrice",3,taxIncludedPrice,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUTNUMBER,514098,"priceWithoutTax",2,priceWithoutTax,2);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,382639,"checkCode",2,checkCode,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131490,"seller",2,seller,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,131491,"purchaser",2,purchaser,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,"131490,389934","salesTaxNo",2,salesTaxNo,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,"131491,389934","purchaserTaxNo",2,purchaserTaxNo,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,505745,"kind",2,kind,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,716,"category",2,category,0);


                String sellerAddress="";
                String purchaserAddress="";
                String salesBank="";
                String purchaserBank="";
                rs2.executeQuery("select * from FnaInvoiceLedgerDtl where mainid = ?",invoiceId);
                if(rs2.next()){
                    sellerAddress = Util.null2String(rs2.getString("sellerAddress"));
                    purchaserAddress = Util.null2String(rs2.getString("purchaserAddress"));
                    salesBank = Util.null2String(rs2.getString("salesBank"));
                    purchaserBank = Util.null2String(rs2.getString("purchaserBank"));
                }
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529910,"sellerAddress",2,sellerAddress,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529911,"purchaserAddress",2,purchaserAddress,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529912,"salesBank",2,salesBank,0);
                this.getSearchConditionItem(itemlist,conditionFactory,ConditionType.INPUT,529913,"purchaserBank",2,purchaserBank,0);

                showSave=true;
            }
            result.put("showSave",showSave);
            result.put("showCheck",showCheck);
            result.put("showDelete",showDelete);
        }

        groupitem.put("defaultshow", true);
        groupitem.put("items", itemlist);
        grouplist.add(groupitem);
        result.put(FnaConstant.FNA_RESULT_CONDITIONS, grouplist);
        result.put("type",invoiceType);
        result.put("flag",true);
        result.put("info", "");

        return result;
    }

    /**
     * 单个发票查验
     * @param params
     * @param user
     * @return
     */
    public JSONObject authenticityCheck(Map<String,Object> params, User user,String ipAdress) throws Exception {
        BaseBean bb =new BaseBean();
        bb.writeLog("开始手动查验！");
        boolean existsInterface = InvoiceUtil.ifExistsInterface(user);
        FnaInvoiceCommon fnaInvoiceCommon = new FnaInvoiceCommon();
        if(!existsInterface){
            throw new Exception(SystemEnv.getHtmlLabelName(384842,user.getLanguage()));
        }
        String result = Util.null2String(params.get("result"));
        bb.writeLog("result=="+result);
        //判断此张发票是否已经存在
        RecordSet rs = new RecordSet();
        String invoiceId = Util.null2String(params.get("invoiceId"));

        //校验是否是自己的发票
        checkInvoiceBelongs(user,invoiceId);


        String invoiceCode = result.split(",")[2];//发票代码
        String invoiceNumber = result.split(",")[3];//发票号码
        rs.executeQuery("select invoiceType from FnaInvoiceLedger where invoiceCode = ? and invoiceNumber = ? and id <> ?", invoiceCode,invoiceNumber,invoiceId);
        if(rs.next()){
            int invoiceType = Util.getIntValue(rs.getString("invoiceType"));
            String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", invoiceNumber)
                    .replace("${invoiceType}", Constants.INVOICETYPE.get(invoiceType));
            throw new Exception(msg);
        }

        FnaAbstractInterface fnaAbstractInterface = new FnaInvoiceCommon().getInterface(user);
        JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result,null);
        int checkstatus = resultObj.getInt("status");
        JSONObject resultJson = new JSONObject();
        if(checkstatus == 0){//失败
            resultJson.put("flag", false);
            if(resultObj.containsKey("errMsg")){
                resultJson.put("msg", resultObj.getString("errMsg"));
            }else{
                resultJson.put("msg", SystemEnv.getHtmlLabelName(509478, user.getLanguage()));//查验失败!
            }

            rs.executeUpdate("update fnaInvoiceLedger set authenticity=?,checkStatus=? where id=?",AUTHENTICITY_FALSE,checkStatus_3,invoiceId);

        }else{
            //首先判断当前发票的发票类型
            rs.executeQuery("select invoiceType from FnaInvoiceLedger where id=?",invoiceId);
            String invoiceType ="";
            if(rs.next()){
                invoiceType=Util.null2String(rs.getString("invoiceType"));
            }
            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_ELEC_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 _billingDate = resultObj.getString("_billingDate");
                String _invoicecode = resultObj.getString("_invoicecode");
                String _checkCode = resultObj.getString("_checkCode");
                String checkCodeSix = "";
                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){
                        resultJson.put("flag", false);
                        resultJson.put("msg", SystemEnv.getHtmlLabelName(390260,user.getLanguage()));
                        return resultJson;
                    }

                    //插入日志1
                    Map<String, String> labelIdMap = new HashMap<String, String>();
                    Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceId),labelIdMap);

                    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,Util.getIntValue(invoiceId),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);
                    JSONArray detaildata = resultObj.getJSONArray("detaildata");
                    InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceId);

                    //插入日志2
                    Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceId),labelIdMap);
                    fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",String.valueOf(invoiceId),"1",
                            beforeMap,afterMap,labelIdMap);
                }
                JSONObject dataJson = new JSONObject();
                dataJson.put("invoiceId", invoiceId);
                dataJson.put("invoiceNumber", _invoiceNumber);
                dataJson.put("billingDate", _billingDate1);
                dataJson.put("taxIncludedPrice", _taxIncludedPrice);
                dataJson.put("description", Constants.INVOICETYPE.get(invoiceType));
                dataJson.put("state","3");//前端需求
                resultJson.put("data", dataJson);
                resultJson.put("flag", true);

            }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");

                if(!fnaInvoiceCommon.ifExistAuthenticity2(invoiceNumberTrue, invoicecodeTrue, new RecordSet())){

                    //插入日志1
                    Map<String, String> labelIdMap = new HashMap<String, String>();
                    Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceId),labelIdMap);

                    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,Util.getIntValue(invoiceId,0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);

                    //插入明细
                    InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),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);
                }

                JSONObject dataJson = new JSONObject();
                dataJson.put("invoiceId", invoiceId);
                dataJson.put("invoiceNumber", invoiceNumberTrue);
                dataJson.put("billingDate", billingDateTrue);
                dataJson.put("taxIncludedPrice", taxIncludedPriceTrue);
                dataJson.put("description", Constants.INVOICETYPE.get(invoiceType));
                dataJson.put("state","3");//前端需求
                resultJson.put("data", dataJson);
                resultJson.put("flag", true);

            }

        }
        bb.writeLog("手动查验返回resultJson=="+resultJson);
        return resultJson;
    }

    /**
     * 删除发票
     * @param params
     * @param user
     * @return
     */
    public JSONObject deleteInvoice(Map<String,Object> params, User user,String ipAdress) throws Exception {
        String invoiceId = Util.null2String(params.get("invoiceId"));
        RecordSet rs = new RecordSet();
        checkInvoiceBelongs(user,invoiceId);
        String type = "0";
        rs.executeQuery("select invoiceType,status from fnainvoiceledger where id = ?", invoiceId);
        if(rs.next()){
            type = Util.null2String(rs.getString("invoiceType"));
        }

        String msg = FnaInvoiceCommon.canDeleteInvoice(false, user, invoiceId);
        if(!"".equals(msg)){
            throw new Exception(msg);
        }

        //插入日志
        Map<String, String> labelIdMap = new HashMap<String, String>();
        Map<String, String> beforeMap =fnaLogSqlUtil.getInvoiceMap(invoiceId,labelIdMap);
        Map<String, String> afterMap = new HashMap<String, String>();
        fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"1",invoiceId,"0",
                beforeMap,afterMap,labelIdMap);

        String deleteSql = "";
        String deleteSqlDtl = "";

        if(VAT_ORDINARY_TYPE.equals(type) || VAT_SPECIAL_TYPE.equals(type) || VAT_Electronic_Type.equals(type) || VAT_ORDINARY_Volume_TYPE.equals(type) || MOTORVEHICLESALES_TYPE.equals(type) || VAT_Electronic_Tolls_Type.equals(type)
        		|| VAT_Electronic_SPECIAL_Type.equals(type)){//增值税发票
            deleteSql = "delete from FnaInvoiceLedgerDetail where mainid = ?";
        }else if(MOTORVEHICLESALES_TYPE.equals(type)){//机动车销售统一发票
            deleteSql = "delete from motor_VehicleInvoice where mainid = ?";
        }else if(USEDCARSALES_TYPE.equals(type)){//二手车销售统一发票
            deleteSql = "delete from second_carInvoice where mainid = ?";
        }else if(QUOTA_TYPE.equals(type)){//定额发票
        }else if(GENERALMACHINE_TYPE.equals(type)){//机打发票
            deleteSql = "delete from machineInvoice where mainid = ?";
        }else if(TAXI_TYPE.equals(type)){//出租车发票
            deleteSql = "delete from taxiInvoice where mainid = ?";
        }else if(TRAIN_TYPE.equals(type)){//火车票
            deleteSql = "delete from trainInvoice where mainid = ?";
        }else if(PASSENGERTICKET_TYPE.equals(type)){//客运汽车
            deleteSql = "delete from carInvoice where mainid = ?";
        }else if(AIRTRANSPORTTICKET_TYPE.equals(type)){//航空运输电子客票行程单
            deleteSql = "delete from airInvoice where mainid = ?";
            deleteSqlDtl = "delete from airDtlInvoice where mainid = ?";
        }else if(TOLLS_TYPE.equals(type)){//过路费发票
            deleteSql = "delete from tollInvoice where mainid = ?";
        }
        if(!"".equals(deleteSql)){
            rs.executeUpdate(deleteSql, invoiceId);
        }
        if(!"".equals(deleteSqlDtl)){
            rs.executeUpdate(deleteSqlDtl, invoiceId);
        }

        rs.executeUpdate("delete from FnaInvoiceLedgerDetail where mainid = ?",invoiceId);
        rs.executeUpdate("delete from fnainvoiceLedger where id = ?", invoiceId);
        JSONObject resultJson = new JSONObject();
        resultJson.put("flag", true);
        return resultJson;
    }


    /**
     * 保存发票
     * @param params
     * @param user
     * @return
     */
    public JSONObject  saveInvoice(Map<String,Object> params, User user,String ipAdress) throws Exception {
        JSONObject resultJson = new JSONObject();

        String invoiceId = Util.null2String(params.get("invoiceId"));
        checkInvoiceBelongs(user,invoiceId);
        
        RecordSet rs = new RecordSet();
        int status = 0;
        rs.executeQuery("select status from fnainvoiceLedger where id = ?", invoiceId);
        if(rs.next()){
        	status = Util.getIntValue(rs.getString("status"));
        }
        if(status!=0) {
        	throw new Exception(SystemEnv.getHtmlLabelName(536451, user.getLanguage()));
        }
		//去重校验控制逻辑
		int workflowlogic = ReimbursementUtil.getWorkflowlogic();
		if(workflowlogic==3) {
			rs.executeQuery("select 1 from FnaInvoiceReimbursement where mainid = ?", invoiceId);
			if(rs.next()) {
	        	throw new Exception(SystemEnv.getHtmlLabelName(536451, user.getLanguage()));
			}
		}

        //发票基本信息
        String invoiceType = Util.null2String(params.get("type"));
        String invoiceCode = Util.null2String(params.get("invoiceCode"));
        String invoiceNumber = Util.null2String(params.get("invoiceNumber"));
        String billingDate = Util.null2String(params.get("billingDate"));
        String priceWithoutTax = df.format(Util.getDoubleValue(Util.null2String(params.get("priceWithoutTax")),0.00));
        String taxIncludedPrice = df.format(Util.getDoubleValue(Util.null2String(params.get("taxIncludedPrice")),0.00));
        String checkCode = Util.null2String(params.get("checkCode"));
        if(AIRTRANSPORTTICKET_TYPE.equals(invoiceType) || TRAIN_TYPE.equals(invoiceType)){//飞机票和火车票无发票代码，默认发票代码等于发票号码
            invoiceCode = invoiceNumber;
        }
        if(!INTERNATIONAL_RECEIPTS.equals(invoiceType)){
            rs.executeQuery("select 1 from fnainvoiceLedger where invoicenumber = ? and invoiceCode= ? and id <> ?", invoiceNumber,invoiceCode,invoiceId);
            if(rs.next()){
                throw new Exception(SystemEnv.getHtmlLabelName(509492, user.getLanguage()));//已存在发票号码相同的发票!
            }
        }

        //插入日志1
        Map<String, String> labelIdMap = new HashMap<String, String>();
        Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceId,labelIdMap);

        if(VAT_ORDINARY_TYPE.equals(invoiceType) || VAT_Electronic_Type.equals(invoiceType) || VAT_ORDINARY_Volume_TYPE.equals(invoiceType) || VAT_Electronic_Tolls_Type.equals(invoiceType)
        		){//增值税普通发票
            String seller = Util.null2String(params.get("seller"));
            String purchaser = Util.null2String(params.get("purchaser"));
            String salesTaxNo = Util.null2String(params.get("salesTaxNo"));
            String purchaserTaxNo = Util.null2String(params.get("purchaserTaxNo"));
            String category = Util.null2String(params.get("category"));
            String kind = Util.null2String(params.get("kind"));
            rs.executeUpdate("update fnainvoiceLedger set invoiceCode=?,invoiceNumber=?,billingDate=?,priceWithoutTax=?,taxIncludedPrice=?," +
                    "checkCode=?,seller=?,purchaser=?,salesTaxNo=?,purchaserTaxNo=?,category=?,kind=? where id=?",
                    invoiceCode,invoiceNumber,billingDate,priceWithoutTax,taxIncludedPrice,checkCode,seller,purchaser,salesTaxNo,purchaserTaxNo,category,kind,invoiceId);

            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

        }else if(VAT_SPECIAL_TYPE.equals(invoiceType) || VAT_Electronic_SPECIAL_Type.equals(invoiceType)){//增值税专用发票
            String seller = Util.null2String(params.get("seller"));
            String purchaser = Util.null2String(params.get("purchaser"));
            String salesTaxNo = Util.null2String(params.get("salesTaxNo"));
            String purchaserTaxNo = Util.null2String(params.get("purchaserTaxNo"));
            String tax = df.format(Util.getDoubleValue(Util.null2String(params.get("tax")),0.00));
            int taxRate = Util.getIntValue(Util.null2String(params.get("taxRate")),0);
            int company_seal = Util.getIntValue(Util.null2String(params.get("company_seal")),0);
            String form_type = Util.null2String(params.get("form_type"));
            String form_name = Util.null2String(params.get("form_name"));
            String kind = Util.null2String(params.get("kind"));
            rs.executeUpdate("update fnainvoiceLedger set invoiceCode=?,invoiceNumber=?,billingDate=?,priceWithoutTax=?,taxIncludedPrice=?," +
                    "seller=?,purchaser=?,salesTaxNo=?,purchaserTaxNo=?,tax=?,taxRate=?,company_seal=?,form_type=?,form_name=?,kind=? where id=?",
                    invoiceCode,invoiceNumber,billingDate,priceWithoutTax,taxIncludedPrice,seller,purchaser,salesTaxNo,purchaserTaxNo,tax,taxRate,company_seal,form_type,form_name,kind,invoiceId);
            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

        }else if(MOTORVEHICLESALES_TYPE.equals(invoiceType)) {//机动车销售统一发票
            String seller = Util.null2String(params.get("seller"));
            String purchaser = Util.null2String(params.get("purchaser"));
            String tax = df.format(Util.getDoubleValue(taxIncludedPrice,0.00)-Util.getDoubleValue(priceWithoutTax,0.00));
            String taxRate="0.00";
            if(Util.getDoubleValue(priceWithoutTax,0.00)!=0){
                taxRate = df.format((Util.getDoubleValue(tax,0.00)/Util.getDoubleValue(priceWithoutTax,0.00))*100);
            }
            rs.executeUpdate("update FnaInvoiceLedger set billingDate = ?,taxIncludedPrice=?,invoiceNumber=?,invoiceCode=?,priceWithoutTax=?,tax=?,taxRate=?,seller=?,purchaser=? where id = ?",
                    billingDate,taxIncludedPrice,invoiceNumber,invoiceCode,priceWithoutTax,tax,taxRate,seller,purchaser,invoiceId);
            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),df.format(priceWithoutTax),taxRate,tax,1,df.format(priceWithoutTax),df.format(priceWithoutTax),"","");

        }else if(USEDCARSALES_TYPE.equals(invoiceType)) {//二手车销售统一发票
            String seller_id = Util.null2String(params.get("seller_id"));
            String buyer_id = Util.null2String(params.get("buyer_id"));
            String company_name = Util.null2String(params.get("company_name"));
            String company_tax_id = Util.null2String(params.get("company_tax_id"));
            String license_plate = Util.null2String(params.get("license_plate"));
            String registration_number = Util.null2String(params.get("registration_number"));
            String car_code = Util.null2String(params.get("car_code"));
            String car_model = Util.null2String(params.get("car_model"));

            rs.executeUpdate("update FnaInvoiceLedger set billingDate = ?,taxIncludedPrice=?,invoiceNumber=?,invoiceCode=? where id=?", billingDate,taxIncludedPrice,invoiceNumber,invoiceCode,invoiceId);

            rs.executeQuery("select 1 from second_carInvoice where mainid = ?", invoiceId);
            if(rs.next()){
                rs.executeUpdate("update second_carInvoice set seller_id=?,buyer_id=?,company_name=?,"+
                                " company_tax_id=?,license_plate=?,registration_number=?,car_code=?,car_model=? where mainid=? ",
                        StringEscapeUtils.escapeSql(seller_id),StringEscapeUtils.escapeSql(buyer_id),StringEscapeUtils.escapeSql(company_name),
                        company_tax_id,license_plate,registration_number,car_code,car_model,invoiceId);
            }else{
                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(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

        }else if(QUOTA_TYPE.equals(invoiceType)) {//定额发票
            String kind = Util.null2String(rs.getString("kind"));//发票消费类型
            rs.executeUpdate("update FnaInvoiceLedger set taxIncludedPrice=?,invoiceNumber=?,invoiceCode=?,kind=? where id=?", taxIncludedPrice,invoiceNumber,invoiceCode,kind,invoiceId);
            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

        }else if(GENERALMACHINE_TYPE.equals(invoiceType)) {//机打发票
            String seller = Util.null2String(params.get("seller"));
            String purchaser = Util.null2String(params.get("purchaser"));
            String time = Util.null2String(params.get("time"));
            String category = Util.null2String(params.get("category"));
            String salesTaxNo=Util.null2String(params.get("salesTaxNo"));
            String purchaserTaxNo=Util.null2String(params.get("purchaserTaxNo"));
            String kind = Util.null2String(params.get("kind"));
            String sellerAddress = Util.null2String(params.get("sellerAddress"));
            String purchaserAddress = Util.null2String(params.get("purchaserAddress"));
            String salesBank = Util.null2String(params.get("salesBank"));
            String purchaserBank = Util.null2String(params.get("purchaserBank"));

            rs.executeUpdate("update FnaInvoiceLedger set billingDate=?,taxIncludedPrice=?,invoiceNumber=?,invoiceCode=?,checkCode=?,seller=?,purchaser=?,kind=?,salesTaxNo=?,purchaserTaxNo=? where id=?",
                    billingDate,taxIncludedPrice,invoiceNumber,invoiceCode,checkCode,seller,purchaser,kind,salesTaxNo,purchaserTaxNo,invoiceId);

            rs.executeQuery("select 1 from machineInvoice where mainid = ?", invoiceId);
            if(rs.next()){
                rs.executeUpdate("update machineInvoice set time=?,category=?,seller_tax_id=?,buyer_tax_id=? where mainid=? ",
                        time,category,salesTaxNo,purchaserTaxNo,invoiceId);
            }else{
                String insertMachine = "insert into machineInvoice(mainid,time,category,seller_tax_id,buyer_tax_id) values(?,?,?,?,?)";
                rs.executeUpdate(insertMachine, invoiceId,time,category,salesTaxNo,purchaserTaxNo);
            }
            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");
            InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1, Util.getIntValue(invoiceId,0), "", "", sellerAddress, purchaserAddress, salesBank, purchaserBank);
        }else if(TAXI_TYPE.equals(invoiceType)) {//出租车发票
            String time_geton = Util.null2String(params.get("time_geton"));
            String time_getoff = Util.null2String(params.get("time_getoff"));
            String mileage = df.format(Util.getDoubleValue(Util.null2String(params.get("mileage")),0.00));
            String place = Util.null2String(params.get("place"));
            String kind = Util.null2String(rs.getString("kind"));//发票消费类型
            rs.executeUpdate("update FnaInvoiceLedger set billingDate=?,taxIncludedPrice=?,invoiceNumber=?,invoiceCode=?,kind=? where id=?",
                    billingDate,taxIncludedPrice,invoiceNumber,invoiceCode,kind,invoiceId);

            rs.executeQuery("select 1 from taxiInvoice where mainid = ?", invoiceId);
            if(rs.next()){
                rs.executeUpdate("update taxiInvoice set time_geton=?,time_getoff=?,mileage=?,place=? where mainid=? ",
                        StringEscapeUtils.escapeSql(time_geton),StringEscapeUtils.escapeSql(time_getoff),
                        StringEscapeUtils.escapeSql(mileage),StringEscapeUtils.escapeSql(place),invoiceId);
            }else{
                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(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

        }else if(TRAIN_TYPE.equals(invoiceType)) {//火车票
            String time = Util.null2String(params.get("time"));
            String name = Util.null2String(params.get("name"));
            String station_geton = Util.null2String(params.get("station_geton"));
            String station_getoff = Util.null2String(params.get("station_getoff"));
            String train_number = Util.null2String(params.get("train_number"));
            String seat = Util.null2String(params.get("seat"));
            String kind = Util.null2String(params.get("kind"));


            //计算进项税额
            String taxRate="9";
            String tax = df.format(Util.getDoubleValue(taxIncludedPrice,0.00) / (1+0.09) * 0.09);
            if("".equals(name)){
                tax = "0.00";
                taxRate="0";
            }
            String pricewithouttax = df.format(Util.getDoubleValue(taxIncludedPrice)-Util.getDoubleValue(tax));
            rs.executeUpdate("update FnaInvoiceLedger set billingDate=?,taxIncludedPrice=?,pricewithouttax=?,invoiceNumber=?,invoiceCode=?,tax=?,taxRate=?,kind=? where id=?",
                    billingDate,taxIncludedPrice,pricewithouttax,invoiceNumber,invoiceNumber,tax,taxRate,kind,invoiceId);

            rs.executeQuery("select 1 from trainInvoice where mainid = ?", invoiceId);
            if(rs.next()){
                rs.executeUpdate("update trainInvoice set time=?,name=?,station_geton=?,station_getoff=?,train_number=?,seat=? where mainid=? ",
                        StringEscapeUtils.escapeSql(time),StringEscapeUtils.escapeSql(name),
                        StringEscapeUtils.escapeSql(station_geton),StringEscapeUtils.escapeSql(station_getoff),
                        StringEscapeUtils.escapeSql(train_number),StringEscapeUtils.escapeSql(seat),invoiceId);
            }else{
                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(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");

        }else if(PASSENGERTICKET_TYPE.equals(invoiceType)) {//客运汽车

            String time = Util.null2String(params.get("time"));
            String name = Util.null2String(params.get("name"));
            String station_geton = Util.null2String(params.get("station_geton"));
            String station_getoff = Util.null2String(params.get("station_getoff"));
            String kind = Util.null2String(params.get("kind"));

            //计算进项税额
            String taxRate="3";
            String tax = df.format(Util.getDoubleValue(taxIncludedPrice,0.00) / (1+0.03) * 0.03);
            if("".equals(name)){
                tax = "0.00";
                taxRate="0";
            }
            String pricewithouttax = df.format(Util.getDoubleValue(taxIncludedPrice)-Util.getDoubleValue(tax));
            rs.executeUpdate("update FnaInvoiceLedger set billingDate=?,taxIncludedPrice=?,pricewithouttax=?,invoiceNumber=?,invoiceCode=?,tax=?,taxRate=?,kind=? where id=?",
                    billingDate,taxIncludedPrice,pricewithouttax,invoiceNumber,invoiceNumber,tax,taxRate,kind,invoiceId);


            rs.executeQuery("select 1 from carInvoice where mainid = ?", invoiceId);
            if(rs.next()){
                rs.executeUpdate("update carInvoice set time=?,name=?,station_geton=?,station_getoff=? where mainid=? ",
                        StringEscapeUtils.escapeSql(time),StringEscapeUtils.escapeSql(name),
                        StringEscapeUtils.escapeSql(station_geton),StringEscapeUtils.escapeSql(station_getoff),invoiceId);
            }else{
                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(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");

        }else if(AIRTRANSPORTTICKET_TYPE.equals(invoiceType)) {//航空运输电子客票行程单

            String user_name = Util.null2String(params.get("user_name"));
            String user_id = Util.null2String(params.get("user_id"));
            String agentcode = Util.null2String(params.get("agentcode"));
            String issue_by = Util.null2String(params.get("issue_by"));

            String fare = df.format(Util.getDoubleValue(Util.null2String(params.get("fare")),0.00));
            String fuel_surcharge = df.format(Util.getDoubleValue(Util.null2String(params.get("fuel_surcharge")),0.00));
            String caac_development_fund = df.format(Util.getDoubleValue(Util.null2String(params.get("caac_development_fund")),0.00));
            String insurance = Util.null2String(params.get("insurance"));

            String kind = Util.null2String(params.get("kind"));
            //计算进项税额
            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(taxIncludedPrice)-Util.getDoubleValue(tax));
            rs.executeUpdate("update FnaInvoiceLedger set billingDate=?,taxIncludedPrice=?,pricewithouttax=?,invoiceNumber=?,invoiceCode=?,tax=?,taxRate=?,kind=? where id=?",
                    billingDate,taxIncludedPrice,pricewithouttax,invoiceNumber,invoiceNumber,tax,taxRate,kind,invoiceId);

            rs.executeQuery("select 1 from airInvoice where mainid = ?", invoiceId);
            if(rs.next()){
                rs.executeUpdate("update airInvoice set user_name=?,user_id=?,agentcode=?,issue_by=?,fare=?,fuel_surcharge=?,caac_development_fund=?,insurance=? where mainid=? ",
                        StringEscapeUtils.escapeSql(user_name),StringEscapeUtils.escapeSql(user_id),
                        StringEscapeUtils.escapeSql(agentcode),StringEscapeUtils.escapeSql(issue_by),fare,fuel_surcharge,caac_development_fund,insurance,invoiceId);
            }else{
                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);
            }

            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");

        }else if(TOLLS_TYPE.equals(invoiceType)) {//过路费发票

            String time = Util.null2String(params.get("time"));
            String entrance = Util.null2String(params.get("entrance"));
            String exit = Util.null2String(params.get("exit"));

            String kind = Util.null2String(params.get("kind"));
            rs.executeUpdate("update FnaInvoiceLedger set billingDate=?,taxIncludedPrice=?,invoiceNumber=?,invoiceCode=?,kind=? where id=?",
                    billingDate,taxIncludedPrice,invoiceNumber,invoiceCode,kind,invoiceId);

            rs.executeQuery("select 1 from tollInvoice where mainid = ?", invoiceId);
            if(rs.next()){
                rs.executeUpdate("update tollInvoice set time=?,entrance=?,export=? where mainid=? ",
                        StringEscapeUtils.escapeSql(time),StringEscapeUtils.escapeSql(entrance),
                        StringEscapeUtils.escapeSql(exit),invoiceId);
            }else{
                String insertToll = "insert into tollInvoice(mainid,time,entrance,export) values(?,?,?,?)";
                rs.executeUpdate(insertToll, invoiceId,time,entrance,exit);
            }

            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

        }else if(INTERNATIONAL_RECEIPTS.equals(invoiceType)) {//国际小票
            String storename = Util.null2String(params.get("storename"));
            String time = Util.null2String(params.get("time"));
            String discount = df.format(Util.getDoubleValue(Util.null2String(params.get("discount")),0.00));
            String tips = Util.null2String(params.get("tips"));
            String currency_code = Util.null2String(params.get("currency_code"));
            String xftype = Util.null2String(params.get("xftype"));

            rs.executeUpdate("update fnainvoiceledger set billingDate=?,taxIncludedPrice=?,priceWithoutTax=? where id = ?",
                    billingDate,taxIncludedPrice,priceWithoutTax,invoiceId);
            rs.executeUpdate("update smallInvoice set storename=?,time=?,discount=?,tips=?,currency_code=?,type=? where mainid = ?",
                    storename,time,discount,tips,currency_code,xftype,invoiceId);

            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");
        }else if(OTHERS_TYPE.equals(invoiceType)) {//可报销的其他发票
            String kind = Util.null2String(params.get("kind"));
            String seller = Util.null2String(params.get("seller"));
            String purchaser = Util.null2String(params.get("purchaser"));
            String salesTaxNo = Util.null2String(params.get("salesTaxNo"));
            String purchaserTaxNo = Util.null2String(params.get("purchaserTaxNo"));
            String sellerAddress = Util.null2String(params.get("sellerAddress"));
            String purchaserAddress = Util.null2String(params.get("purchaserAddress"));
            String salesBank = Util.null2String(params.get("salesBank"));
            String purchaserBank = Util.null2String(params.get("purchaserBank"));

            rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,kind=?,seller=?,purchaser=?,salesTaxNo=?,purchaserTaxNo=? where id=?",
                    invoiceCode,invoiceNumber,billingDate,df.format(Util.getDoubleValue(taxIncludedPrice)),kind,seller,purchaser,salesTaxNo,purchaserTaxNo,invoiceId);
            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");
            InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1, Util.getIntValue(invoiceId,0), "", "", sellerAddress, purchaserAddress, salesBank, purchaserBank);
        }else if(TAX_CERTIFICATE_TYPE.equals(invoiceType)) {//完税证明
            String purchaser = Util.null2String(params.get("purchaser"));
            String purchaserTaxNo = Util.null2String(params.get("purchaserTaxNo"));

            rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,purchaser=?,purchaserTaxNo=? where id=?",
                    invoiceCode,invoiceNumber,billingDate,df.format(Util.getDoubleValue(taxIncludedPrice)),purchaser,purchaserTaxNo,invoiceId);

            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");
        }else if(BLOCKCHAIN_TYPE.equals(invoiceType)) {//区块链

            String purchaser = Util.null2String(params.get("purchaser"));
            String purchaserTaxNo = Util.null2String(params.get("purchaserTaxNo"));
            String seller = Util.null2String(params.get("seller"));
            String salesTaxNo = Util.null2String(params.get("salesTaxNo"));
            String kind = Util.null2String(params.get("kind"));
            String category = Util.null2String(params.get("category"));

            String sellerAddress = Util.null2String(params.get("sellerAddress"));
            String purchaserAddress = Util.null2String(params.get("purchaserAddress"));
            String salesBank = Util.null2String(params.get("salesBank"));
            String purchaserBank = Util.null2String(params.get("purchaserBank"));

            double tax=Util.getDoubleValue(taxIncludedPrice,0)-Util.getDoubleValue(priceWithoutTax,0);
            double taxRate =0.00;
            if(tax!=0 && Util.getDoubleValue(priceWithoutTax,0)!=0){
                taxRate = (tax/Util.getDoubleValue(priceWithoutTax)*100);
            }
            rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,priceWithoutTax=?,tax=?,taxRate=?,checkcode=?,purchaser=?,purchaserTaxNo=?," +
                            " seller=?,salesTaxNo=?,kind=?,category=? where id=?",
                    invoiceCode,invoiceNumber,billingDate,df.format(Util.getDoubleValue(taxIncludedPrice)),df.format(Util.getDoubleValue(priceWithoutTax)),df.format(tax),df.format(taxRate),checkCode,purchaser,purchaserTaxNo,
                    seller,salesTaxNo,kind,category,invoiceId);

            //插入明细
            InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceId,0),Constants.INVOICESERVICEYYPE.get(invoiceType),df.format(Util.getDoubleValue(priceWithoutTax, 0.00)),df.format(taxRate),df.format(tax),1,df.format(Util.getDoubleValue(priceWithoutTax, 0.00)),df.format(Util.getDoubleValue(priceWithoutTax, 0.00)),"","");
            InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1, Util.getIntValue(invoiceId,0), "", "", sellerAddress, purchaserAddress, salesBank, purchaserBank);
        }

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

        JSONObject dataJson = new JSONObject();
        String invoiceNumberBack = "";
        String billingDateBack = "";
        String taxIncludedPriceBack = "";
        String invoiceTypeBack="";
        rs.executeQuery("select * from fnainvoiceledger where id=?",invoiceId);
        if(rs.next()){
            invoiceNumberBack = Util.null2String(rs.getString("invoiceNumber"));
            billingDateBack = Util.null2String(rs.getString("billingDate"));
            invoiceTypeBack = Util.null2String(rs.getString("invoiceType"));
            taxIncludedPriceBack = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
        }
        dataJson.put("invoiceNumber",invoiceNumberBack);
        dataJson.put("billingDate",billingDateBack);
        dataJson.put("taxIncludedPrice",taxIncludedPriceBack);
        dataJson.put("description", Constants.INVOICETYPE.get(invoiceTypeBack));
        dataJson.put("invoiceId",invoiceId);
        dataJson.put("state","1");//前端需求
        resultJson.put("flag",true);
        resultJson.put("data",dataJson);
        return resultJson;
    }
    /**
     * 获取SearchConditionItem，赋值给itemlist
     * @param conditionType
     * @param labelId
     * @param name
     * @param viewAttr
     * @param value
     * @param itemlist
     * @param conditionFactory
     * @param precision 保留几位小数
     */
     public void getSearchConditionItem(List<SearchConditionItem> itemlist,ConditionFactory conditionFactory,
                                        ConditionType conditionType,int labelId,String name,int viewAttr,String value,int precision){
         SearchConditionItem objItem = conditionFactory.createCondition(conditionType, labelId, name);
         objItem.setViewAttr(viewAttr);
         objItem.setValue(value);
         if(precision>0){
             objItem.setPrecision(precision);
         }
         itemlist.add(objItem);

     }

    /**
     * 获取SearchConditionItem，赋值给itemlist
     * @param conditionType
     * @param labelId
     * @param name
     * @param viewAttr
     * @param value
     * @param itemlist
     * @param conditionFactory
     */
    public void getSearchConditionItem(List<SearchConditionItem> itemlist,ConditionFactory conditionFactory,
                                       ConditionType conditionType,String labelIds,String name,int viewAttr,String value,int precision){
        SearchConditionItem objItem = conditionFactory.createCondition(conditionType, labelIds, name);
        objItem.setViewAttr(viewAttr);
        objItem.setValue(value);
        if(precision>0){
            objItem.setPrecision(precision);
        }
        itemlist.add(objItem);

    }

    /**
     * 添加发票显示信息
     * @param jsonObject
     * @param number
     * @return
     */
    private static JSONObject addShowInfo(JSONObject jsonObject,String number,String code){
        String[] invoceInfo = getInvoiceData(number,code);
        jsonObject.put("invoiceNumber",number);
        jsonObject.put("billingDate",invoceInfo[0]);
        jsonObject.put("taxIncludedPrice",invoceInfo[1]);
        jsonObject.put("priceWithoutTax",invoceInfo[6]);
        jsonObject.put("invoiceCode",invoceInfo[5]);
        jsonObject.put("checkCode",invoceInfo[4]);
        String id = invoceInfo[3]+"";
        jsonObject.put("invoiceId",id);
        return jsonObject;
    }
    /**
     * 获取发票信息
     * @param id
     * @return
     */
    public static String[] getInvoiceData(String invoiceNumber,String invoiceCode){
        RecordSet rs = new RecordSet();
        String[] data = new String[7];
        String sql = "select id,billingDate,taxIncludedPrice,invoiceType,checkCode,invoiceCode,priceWithoutTax from fnaInvoiceLedger where invoiceNumber = ? and invoiceCode = ? ";
        rs.executeQuery(sql, invoiceNumber, invoiceCode);
        String id = "0";
        String billingDate = "";
        String taxIncludedPrice = "";
        String invoiceType = "";
        String checkCode = "";
        String priceWithoutTax = "";
        if(rs.next()){
            id = Util.null2String(rs.getString("id"));
            billingDate = Util.null2String(rs.getString("billingDate"));
            taxIncludedPrice = df.format(Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00));
            invoiceType = Util.null2String(rs.getString("invoiceType"));
            checkCode = Util.null2String(rs.getString("checkCode"));
            priceWithoutTax = df.format(Util.getDoubleValue(rs.getString("priceWithoutTax"),0.00));

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


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

    /**
     * 校验日期格式
     * @param date
     * @return
     */
    public 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;
    }

    /**
     * randomInvoiceNumber
     * @return
     */
    public static String randomInvoiceNumber(){
        int[] number = new int[]{0,1,2,3,4,5,6,7,8,9};
        StringBuffer invoicenumber = new StringBuffer();
        for(int i = 0;i<8;i++){
            invoicenumber.append(number[new Random().nextInt(10)]);
        }
        return invoicenumber.toString();
    }


    /**
     * 获取发票图片
     * @param inputStream
     * @return
     */
    public String changeFileTobase64(InputStream inputStream){
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] fileByte=null;
        String base64String = "";

        try {
            if(null==inputStream){
                return base64String;
            }
            byte[] buffer = new byte[1024*1000];
            int len = -1;
            while((len=inputStream.read(buffer))!=-1){
                outStream.write(buffer,0,len);
            }
            fileByte = outStream.toByteArray();
            inputStream.read(fileByte);
            inputStream.close();
        } catch (Exception e) {
            new BaseBean().writeLog("changeFileTobase64_Exception:"+e.getMessage());
        }
        if(null!=fileByte){
            base64String = Base64.encodeBase64String(fileByte);
        }
        return base64String;
    }

    /**
     * 判断发票是否属于本人
     * @param user
     * @param invoiceId
     * @throws Exception
     */
    public static void checkInvoiceBelongs(User user,String invoiceId) throws Exception{
        RecordSet rs = new RecordSet();
        int userid = user.getUID();
        rs.executeQuery("select * from fnainvoiceLedger where id = ? and userid_new = ?", invoiceId,userid);
        if(rs.getCounts()==0){
            throw new Exception(SystemEnv.getHtmlLabelName(509486, user.getLanguage()));//非本人的发票无法操作!
        }
    }

}
