package com.jeeplus.modules.sg.overheadline.util;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.common.utils.sg.ExcelUtil;
import com.jeeplus.modules.sg.overheadline.entity.JkxlAdjustFee;
import com.jeeplus.modules.sg.overheadline.entity.Settlement;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.text.FieldPosition;
import java.text.NumberFormat;
import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.List;
public class SettementUtil {
    private static final NumberFormat nf= NumberFormat.getInstance();
    public static Boolean getFlag = false;
    public static final String RESON_TRUE="【范围内】&nbsp;金额<span style='color:#0000FF'>&nbsp;一致。</span>";
    public static final String RESON_FLASE="【范围内】金额<span style='color:#FF0000'>&nbsp;不一致。</span>";
    public static final String BDZ_TBRNAME="投标人采购设备费";
    public static final String BDZ_ZBRNAME="招标人采购材料费";
    public static final String BDZ_TBNAME="投标报价";
    public static final String SE= "税额";
    public static final String ST = "税金调差";
    public static final String SE1= "税额调差";
    public static final String RESON_KYJ="扣";
    public static final String RESON_KYJ1="减";
    public static final String RESON_ZZJS="最终结算价";
    public static final String RESON_ZZFC="最终工程造价";
    public static final String RESON_ZGTB="最高投标限价";
    public static final String RESON_FBFXGCF1="建筑工程费";
    public static final String RESON_FBFXGCF2="安装工程费";
    public static final String RESON_XF="下浮";
    public static final String RESON_XFHZJ="下浮后造价";

    /*
        分布分项比对
     */
    public static final String RESON_FBFX1="《工程项目竣工结算汇总表》,分部分项工程费,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_FBFX2="《架空线路工程费用汇总表》,分部分项汇总金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_FBFX3="《分部分项工程量清单计价表》,分部分项汇总金额,<span style='font-weight: bold;'>xxx</span>,";
    //电缆
    public static final String RESON_JZFBFX="《电缆线路建筑工程费用汇总表》,合计金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_AZFBFX="《电缆线路安装工程费用汇总表》,合计金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_JZFBFX3="《建筑分部分项工程量清单计价表》,分部分项汇总金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_AZFBFX3="《安装分部分项工程量清单计价表》,分部分项汇总金额,<span style='font-weight: bold;'>xxx</span>,";
    //变电站
    public static final String BDZ_FXFX="《工程项目投标报价汇总表》,分部分项工程费,<span style='font-weight: bold;'>xxx</span>,";
    public static final String BDZ_FBFX1="《变电站建筑工程费用汇总表》,分部分项汇总金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String BDZ_FBFX2="《变电站安装工程费用汇总表》,分部分项汇总金额,<span style='font-weight: bold;'>xxx</span>,";
    /*
        承包人采购比对
     */
    public static final String RESON_CBRF="《工程项目竣工结算汇总表》,承包人采购设备费,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_CBRF1="《承包人采购设备计价表》,合计金额,<span style='font-weight: bold;'>xxx</span>,";
    //变电站
    public static final String BDZ_TBRCG="《工程项目投标报价汇总表》,投标人采购设备费,<span style='font-weight: bold;'>xxx</span>,";
    public static final String BDZ_TBRCG1="《投标人采购设备计价表》,合计金额,<span style='font-weight: bold;'>xxx</span>,";
    /*
        措施费比对
     */
    public static final String RESON_CSXM="《工程项目竣工结算汇总表》,措施项目费,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_CSXM1="《措施项目清单计价表(一)》,合计金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_CSXM2="《措施项目清单计价表(二)》,合计金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_CSXM3="&nbsp,小计,<span style='font-weight: bold;'>xxx</span>,";
   //变电站
    public static final String BDZ_CSF="《工程项目投标报价汇总表》,措施项目费,<span style='font-weight: bold;'>xxx</span>,";
    /*
        其他项目费比对
     */
    public static final String RESON_QTXM="《工程项目竣工结算汇总表》,其他项目费,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_QTXM1="《其他项目清单计价表》,合计金额,<span style='font-weight: bold;'>xxx</span>,";
    //变电站
    public static final String BDZ_QTXM="《工程项目投标报价汇总表》,其他项目费,<span style='font-weight: bold;'>xxx</span>,";
    public static final String BDZ_QTXM1="《其他项目清单计价表》,合计金额,<span style='font-weight: bold;'>xxx</span>,";
    /*
        规费比对
     */
    public static final String RESON_GF="《工程项目竣工结算汇总表》,规费,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_GF1="《规费项目清单计价表》,合计金额,<span style='font-weight: bold;'>xxx</span>,";
    //变电站
    public static final String BDZ_GF="《工程项目投标报价汇总表》,规费,<span style='font-weight: bold;'>xxx</span>,";
    /*
        税率 不验证
     */
    public static final String RESON_SJ="《工程项目竣工结算汇总表》,税金 (税率: 9%)";
    public static final String BDZ_SJ="《工程项目投标报价汇总表》,税金 (税率: 9%)";
    /*
        发包人采购费
     */
    public static final String RESON_FBRF="《工程项目竣工结算汇总表》,发包人采购材料费,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_FBRF1="《分布分项工程量清单计价表》,发包人采购汇总金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_FBRF2="《分布分项工程量清单计价表》,招标人采购汇总金额,<span style='font-weight: bold;'>xxx</span>,";
    //电缆
    public static final String RESON_DLFBRF1="《建筑分布分项工程量清单计价表》,发包人采购汇总金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_DLFBRF2="《安装分布分项工程量清单计价表》,发包人采购汇总金额,<span style='font-weight: bold;'>xxx</span>,";
    //变电
    public static final String BDZ_FBRF="《工程项目投标报价汇总表》,招标人采购材料费,<span style='font-weight: bold;'>xxx</span>,";
    public static final String BDZ_FBRF1="《建筑分布分项工程量清单计价表》,招标人采购金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String BDZ_FBRF2="《安装分布分项工程量清单计价表》,招标人采购金额,<span style='font-weight: bold;'>xxx</span>,";
    //变电站
    /*
        竣工结算
     */
    public static final String RESON_JGJS="《工程项目竣工结算汇总表》,竣工结算价合计金额,<span style='font-weight: bold;'>xxx</span>,";
    public static final String RESON_JGJS8=",小计,<span style='font-weight: bold;'>xxx</span>,";
    //变电站
    public static final String BDZ_TBBJ="《工程项目投标报价汇总表》,投标报价,<span style='font-weight: bold;'>xxx</span>,";

    /*
       工程结算
    */
    public static final String RESON_GCJS="工程项目汇总表,结算价,<span style='font-weight: bold;'>xxx</span>,";
    public static final String[] DLBDZ_FBFX2 = {RESON_FBFX1,BDZ_FBFX1,BDZ_FBFX2,RESON_JGJS8,RESON_JZFBFX3,RESON_AZFBFX3,RESON_JGJS8};
    public static final String[] DLBDZ_FBFX1 = {RESON_FBFX1,RESON_JZFBFX,RESON_AZFBFX,RESON_JGJS8,RESON_JZFBFX3,RESON_AZFBFX3,RESON_JGJS8};
    /*
        设置转换参数
     */
    static {
        nf.setGroupingUsed(false);
    }
    /**
     * 《工程竣工表》、《工程项目投标表》获取所需要的数据存放在集合当中
     * @param importExcel 表格对象
     * @return 《工程竣工表》/《工程项目投资表》 list集合 集合为汇总表结算比对时所需要的内容
     */
    public static List<Settlement> getComparison(ImportExcel importExcel){
        List<JkxlAdjustFee> jkxlAdjustFees = BashInfo.getWsbFee(importExcel);
        boolean flag = false;//判断 工程表/投标表名称以及字段比较
        boolean flagTotal= true;//判断是否有分部分项 如果没有为true
        double countTotal=0.0;//安装分部分项/建筑分部分项合计金额
        Settlement settlement; //结算汇总对象
        List<Settlement> settlementList = new ArrayList<Settlement>(); //存储对象集合
        int lastDataRowNum =  importExcel.getLastDataRowNum(); //汇总表总长度
        String key = "";//获取结算名称
        Integer count = 0; //计数器 用作税金 默认值为0，当存在一次税金时 count++
        for (int i = 0; i < lastDataRowNum; i++) { //循环当前表格
            settlement=new Settlement(); //常见settlement对象
            key =  importExcel.getValue(i+1,1);//获取汇总表名称
            if (key.contains(BashInfo.JS_SJ)){ //判断key是否为税金
                if (key.contains(ST)){ //如果存在税金并且包含"税金调差"
                    key=ST; //赋值key为税金调差
                }else {
                    key=BashInfo.JS_SJ;//否则key赋值给税金
                }
            }
            if(key.contains(SE)){ //判断是否为税额
                if (key.contains(SE1)){ //如果包含税额调差
                    key=SE1; //key赋值给税额调差
                }else {
                    key=BashInfo.JS_SJ;
                }
            }
            if(key.equals(BDZ_TBRNAME)){//判断是否包含“投标人采购设备费”
                flag=true; //flag为true时说明包含 投标人采购设备费
                key=BashInfo.JS_CBRF; //如果时 赋值key为 “承包人”
            }
            if (key.equals(BDZ_ZBRNAME)){
                flag=true;
                key=BashInfo.JS_FBRF;
            }
            if (key.equals(BDZ_TBNAME)){
                flag=true;
                key=BashInfo.JS_JGJS;
            }
            switch (key){
                case RESON_FBFXGCF1: //如果存在 建筑工程费
                    countTotal+=importExcel.getDouble(i+1,2);//得到金额
                    break;
                case RESON_FBFXGCF2://如果存在 安装工程费
                    countTotal+=importExcel.getDouble(i+1,2);//累加金额
                    break;
                case BashInfo.JS_FBFX: //如果存在 分部分项
                    flagTotal=false; //flagTotal 设置为false 说明分部分项存在
                    settlementList.add(getSettlement(settlement,key,importExcel,i));//存到list中
                    break;
                case BashInfo.JS_CBRF: //如果存在 承包人费
                    if (flag){ //如果为flag为true
                        key=BDZ_TBRNAME;//投标人赋值赋值给key
                        flag=false;
                    }
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
                case BashInfo.JS_CSXM://如果存在措施费存到list中
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
                case BashInfo.JS_QTXM://如果存在其他项目费存到list中
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
                case BashInfo.JS_GF://如果存在规费存在list当中
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
                case BashInfo.JS_SJ://如果存在税金
                    count+=1;//计数器+1
                    if (count>1){//如果count>1则第二次出现税金 进行税金累加替换list当中 存在税金的settement替换金额
                        for (Settlement st:settlementList){
                            if (st.getEntryName().equals(BashInfo.JS_SJ)){
                                double s = importExcel.getDouble(i+1,2);
                                double total = st.getMoney()+s;
                                st.setMoney(total);
                            }
                        }
                    }
                    if (count==1){//如果等于一  税金第一次出现
                        settlementList.add(getSettlement(settlement,key,importExcel,i));//存在集合当中
                        //获取 其他需要的字段 存放集合当中
                        for (JkxlAdjustFee jkxlAdjustFee:jkxlAdjustFees){
                            settlement=new Settlement();
                            settlement.setEntryName(jkxlAdjustFee.getType());
                            settlement.setMoney(jkxlAdjustFee.getFee());
                            settlement.setRemarks("");
                            settlementList.add(settlement);
                        }
                    }
                    break;
                case BashInfo.JS_FBRF://如果存在发包人采购费
                    if (flag){ //如果为 true 则key为招标人采购设备费
                        key=BDZ_ZBRNAME;
                        flag=false;//关闭开关
                    }
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
                case ST://如果为“税金调差”
                    settlementList.add(getSettlement(settlement,ST,importExcel,i));
                    break;
                case SE1://如果为“税额调差”
                    settlementList.add(getSettlement(settlement,ST,importExcel,i));
                    break;
                case BashInfo.JS_JGJS://如果为“竣工结算价合计”
                    if (flag){
                        key=BDZ_TBNAME;
                        flag=false;
                    }
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
                case BashInfo.JS_GCJS://如果为工程结算价
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
                case RESON_ZZFC:
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
                case RESON_ZZJS:
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
                case RESON_ZGTB:
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
                case RESON_XFHZJ:
                    settlementList.add(getSettlement(settlement,key,importExcel,i));
                    break;
            }
        }
        if (flagTotal){//flagTotal为true 则不存在分部分项费
            settlement=new Settlement();
            settlement.setEntryName(BashInfo.JS_FBFX); //赋值settlement 的名称为分部分项费
            settlement.setMoney(countTotal);//countTotal 赋值金额 为countTotal
            settlementList.add(0,settlement);
        }
        return settlementList;
    }

    /**
     * 架空项目  校验
     * @param settlements 工程竣工结算list集合
     * @param builtTotal 获取架空线路工程费用汇总表 分部分项 合计
     * @param divisiontotal 获取分部分项比对数据清单
     * @param wordtotal1 //获取措施费清单计价表1 合计/小计
     * @param wordtotal2 //获取措施费清单计价表2 合计/小计
     * @param otherTotal 获取其他项目费合计 合计/小计
     * @param feescount 获取规费合计
     * @param cbperson 获取承包人采购合计
     * @return 导入架空项目校验后的集合。
     */
    public static List<Settlement> getComparison(List<Settlement> settlements, double builtTotal, double[] divisiontotal, double wordtotal1,double wordtotal2, double otherTotal, double feescount,double cbperson){
        double wordtotal=wordtotal1+wordtotal2;//措施费相加
        String name="";//获取当前汇总表名称
        double money=0.0;//获取当前汇总表金额
        Settlement settlement;//对象
        double moneyComparison1;//范围金额+5.0元
        double moneyComparison2;//范围金额-5.0元
        for (int i = 0; i < settlements.size(); i++) {
            settlement=settlements.get(i);
            name=settlement.getEntryName();
            //读取字段区分
            if(name.equals(BDZ_TBRNAME)){//如果为“投标人采购设备费”
                name=BashInfo.JS_CBRF;//把name赋值 “承包人采购费”
            }
            if (name.equals(BDZ_ZBRNAME)){//如果为 “招标人采购设备费”
                name=BashInfo.JS_FBRF;//赋值 “发包人采购设备费”
            }
            if (name.equals(BDZ_TBNAME)){ //如果为 “投标报价”
                name=BashInfo.JS_JGJS; //赋值 “竣工结算价合计”
            }
            if (name.contains(RESON_KYJ)){ //如果包含“扣”
                name = RESON_KYJ; //赋值 “扣”
            }
            if (name.contains(RESON_KYJ1)){ //如果包含“减”
                name = RESON_KYJ1; //赋值：“减”
            }
            if (name.equals(RESON_ZZJS)){//同上
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_ZZFC)){//同上
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_ZGTB)){//同上
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_XFHZJ)){//同上
                name = BashInfo.JS_GCJS;
            }
            money=settlement.getMoney();//获取对象金额
            moneyComparison1 = money+5.0;//取值范围
            moneyComparison2 = money-5.0;
            settlement.setStatus("1");
            switch (name){
                case BashInfo.JS_FBFX://如果存在分部分项费
                    //builtTotal 架空线路工程费用汇总表 分部分项 合计 divisiontotal[0] 获取分部分项比对数据清单 分部分项费用
                    //判断
                    if(builtTotal<=moneyComparison1&&builtTotal>=moneyComparison2&&divisiontotal[0]<=moneyComparison1&&divisiontotal[0]>=moneyComparison2){
                        settlement.setStatus("0");//一致
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(builtTotal)+","+nf.format(divisiontotal[0])));//存入数据库
                    break;
                case  BashInfo.JS_CBRF://如果存在承包人采购设备费
                    //cbperson 获取承包人采购表合计
                    if(cbperson<=moneyComparison1&&cbperson>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(cbperson)));
                    break;
                case BashInfo.JS_CSXM://如果存在措施项目费
                    //wordtotal 措施费（1），措施费(2)金额相加
                    if(wordtotal<=moneyComparison1&&wordtotal>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(wordtotal1)+","+nf.format(wordtotal2)+","+nf.format(wordtotal)));
                    break;
                case BashInfo.JS_QTXM://如果存在其他项目费
                    //otherTotal 其他项目费合计
                    if(otherTotal<=moneyComparison1&&otherTotal>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(otherTotal)));
                    break;
                case BashInfo.JS_GF://如果存在规费
                    if (feescount<=moneyComparison1&&feescount>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(feescount)));
                    break;
                case BashInfo.JS_SJ:
                    settlement.setStatus("2");//不验证
                    settlement.setTheAmount(String.valueOf(nf.format(money)));
                    break;
                case BashInfo.JS_FBRF: //如果存在发包人费
                    if(divisiontotal[1]<=moneyComparison1&&divisiontotal[1]>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(divisiontotal[1])));
                    break;
                case BashInfo.JS_JGJS://如果存在竣工结算价
                    double doubles = getJgjsComparison(settlements);//获取与竣工结算价比对的金额 doubles为比对金额
                    if (doubles<=moneyComparison1&&doubles>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    String str = String.valueOf(nf.format(doubles));
                    settlement.setTheAmount(str);
                    break;
                case BashInfo.JS_GCJS: //如果存在工程结算价
                    //gcComparison 工程结算价 比对金额
                    double gcComparison =getGcComparison(settlements);
                    if (gcComparison<=moneyComparison1&&gcComparison>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(gcComparison)));
                    break;
                default://如果以上都不匹配
                    settlement.setStatus("2");//设置为不验证
                    break;
            }
        }
        return settlements;
    }

    /**
     * 电缆/变电站 核对 校验规则
     * @param settlements 校验表数据list集合
     * @param builtTotal  建筑、安装 分布分项数组
     * @param divisiontotal 建筑、安装 清单数组
     * @param wordtotal1  措施费一
     * @param wordtotal2  措施费二
     * @param otherTotal  其他项目费
     * @param feescount   规费
     * @param cbperson    发包人 /  招标人 费用
     * @return  电缆/变电站 项目 导入后 校验规则  list集合
     */
    public static List<Settlement> getDLComparison(List<Settlement> settlements, double builtTotal[], double[] divisiontotal, double wordtotal1,double wordtotal2, double otherTotal, double feescount,double cbperson){
        double wordtotal=wordtotal1+wordtotal2;//措施费相加
        String name="";//获取当前汇总表名称
        double money=0.0;//获取当前汇总表金额
        Settlement settlement;//对象
        double moneyComparison1;//范围金额+5.0元
        double moneyComparison2;//范围金额-5.0元
        for (int i = 0; i < settlements.size(); i++) {
            settlement=settlements.get(i);
            name=settlement.getEntryName();
            //读取字段区分
            if(name.equals(BDZ_TBRNAME)){
                name=BashInfo.JS_CBRF;
            }
            if (name.equals(BDZ_ZBRNAME)){
                name=BashInfo.JS_FBRF;
            }
            if (name.equals(BDZ_TBNAME)){
                name=BashInfo.JS_JGJS;
            }
            if (name.contains(RESON_KYJ)){
                name = RESON_KYJ;
            }
            if (name.contains(RESON_KYJ1)){
                name = RESON_KYJ1;
            }
            if (name.equals(RESON_ZZJS)){
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_ZZFC)){
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_ZGTB)){
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_XFHZJ)){
                name = BashInfo.JS_GCJS;
            }
            //获取金额
            money=settlement.getMoney();
            moneyComparison1 = money+5.0;
            moneyComparison2 = money-5.0;
            //默认初始状态为 1-不一致
            settlement.setStatus("1");
            switch (name){
                case BashInfo.JS_FBFX://分部分项工程费
                    double division=divisiontotal[0]+divisiontotal[2];//分工清单分部分项
                    double built = builtTotal[0]+builtTotal[1];//安装合计总金额
                    //比对是否在范围内
                    if(built<=moneyComparison1&&built>=moneyComparison2&&division<=moneyComparison1&&division>=moneyComparison2){
                        settlement.setStatus("0"); //比对结果 一致
                    }
                    //存放字符串 用“,”隔开
                    settlement.setTheAmount(String.valueOf(nf.format(built)+","+nf.format(division)+","+nf.format(builtTotal[0])+","+nf.format(builtTotal[1])+","+nf.format(divisiontotal[0])+","+nf.format(divisiontotal[2])));
                    break;
                case  BashInfo.JS_CBRF://承包人采购设备费
                    //cbperson  发包人/招标人 费用
                    if(cbperson<=moneyComparison1&&cbperson>=moneyComparison2){
                        settlement.setStatus("0");//比对结果 一致
                    }
                    //存放字符串 用“,”隔开
                    settlement.setTheAmount(String.valueOf(nf.format(cbperson)));
                    break;
                case BashInfo.JS_CSXM://措施项目费
                    //wordtotal 措施表1,2相加
                    if (wordtotal<=moneyComparison1&&wordtotal>=moneyComparison2){
                        settlement.setStatus("0");//比对结果 一致
                    }
                    //存放字符串 用“,”隔开
                    settlement.setTheAmount(String.valueOf(nf.format(wordtotal1)+","+nf.format(wordtotal2)+","+nf.format(wordtotal)));
                    break;
                case BashInfo.JS_QTXM://其他项目费
                    //otherTotal 其他费比对金额
                    if(otherTotal<=moneyComparison1&&otherTotal>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(otherTotal)));
                    break;
                case BashInfo.JS_GF://规费
                    //feescount 规费表等到合计金额
                    if (feescount<=moneyComparison1&&feescount>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(feescount)));
                    break;
                case BashInfo.JS_SJ://税金
                    settlement.setStatus("2");//不验证
                    settlement.setTheAmount(String.valueOf(nf.format(money)));
                    break;
                case BashInfo.JS_FBRF://发包人采购材料费
                    double divisionFbr =divisiontotal[1]+divisiontotal[3];//发包人比对金额相加
                    if(divisionFbr<=moneyComparison1&&divisionFbr>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(divisionFbr)+","+nf.format(divisiontotal[1])+","+nf.format(divisiontotal[3])));
                    break;
                case BashInfo.JS_JGJS://竣工结算价合计
                    double doubles = getJgjsComparison(settlements);//获取比对金额
                    if (doubles<=moneyComparison1&&doubles>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    String str = String.valueOf(nf.format(doubles));
                    settlement.setTheAmount(str);
                    break;
                case BashInfo.JS_GCJS://工程结算价
                    double gcComparison =getGcComparison(settlements);//获取比对金额
                    //验证 金额 误差是否在范围内
                    if (gcComparison<=moneyComparison1&&gcComparison>=moneyComparison2){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(nf.format(gcComparison)));
                    break;
                default://如果以上不匹配
                    settlement.setStatus("2");//默认不验证
                    break;
            }
        }
        return settlements;
    }
    /**
     * 架空、电缆、变电站 竣工结算 合计金额 返回值double为竣工结算比对金额
     * @param settlements 《工程项目投标报价汇总表》/《工程项目结算汇总表》 集合
     * @return Double 经过计算后的竣工结算价
     */
    public static Double getJgjsComparison(List<Settlement> settlements){
        double[] doubles = new double[8]; //定义数组 （可改）
        boolean flag= false; //用作判断是否存在 工程结算价/最终结算价 等等。
        String name=""; //settlement对象名称
        double money=0.0;//settlement对象金额
        double minus = 0.0;// 减去的金额合计
        double addcount = 0.0;//加上的金额合计
        double jgjeCount = 0.0;//存放竣工结算价金额
        for (Settlement settlement:settlements){
            name = settlement.getEntryName();
            money = settlement.getMoney();
            if (name.equals(BDZ_TBNAME)){//如果为投标报价
                name=BashInfo.JS_JGJS; //name=竣工结算
            }
            if(name.equals(BDZ_TBRNAME)){//如果为 投标人采购设备费
                name=BashInfo.JS_CBRF; //承包人费
            }
            if (name.equals(BDZ_ZBRNAME)){ //如果为招标人费
                name=BashInfo.JS_FBRF;//发包人采购材料费
            }
            //如果包含 “扣”  “减” “下浮”
            if (name.contains(RESON_KYJ)||name.contains(RESON_XF)||name.contains(RESON_KYJ1)){
                if (!name.equals(RESON_XFHZJ)){//如果 不等于下浮造价
                    name = RESON_KYJ; //赋值name：“扣”
                }
            }
            if (name.equals(RESON_ZZJS)){//工程结算价 兼容
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_ZZFC)){//工程结算价 兼容
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_ZGTB)){//工程结算价 兼容
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_XFHZJ)){//工程结算价 兼容
                name = BashInfo.JS_GCJS;
            }
            switch (name) {
                case BashInfo.JS_FBFX://分部分项工程费
                    doubles[1]=money;
                    break;
                case BashInfo.JS_CBRF://承包人采购设备费
                    doubles[2]=money;
                    break;
                case BashInfo.JS_CSXM://措施项目费
                    doubles[3]=money;
                    break;
                case BashInfo.JS_QTXM://其他项目费
                    doubles[4]=money;
                    break;
                case BashInfo.JS_GF://规费
                    doubles[5]=money;
                    break;
                case BashInfo.JS_SJ://税金
                    doubles[6]=money;
                    break;
                case BashInfo.JS_FBRF://发包人采购材料费
                    doubles[7]=money;
                    break;
                case RESON_KYJ://扣
                    minus += money; //需要减去的金额累加
                    break;
                default: //如果以上不匹配
                    if (name.equals(BashInfo.JS_JGJS)){//如果等于 "竣工结算价合计"
                        jgjeCount=money; //存储  "竣工结算价合计" 金额
                    }else if (!name.equals(BashInfo.JS_GCJS)){ //如果不等于 工程结算价
                        addcount+=money; //需要加上的金额 累加
                    }
                    if (name.equals(BashInfo.JS_GCJS)){ //如果name为 工程结算价
                        flag=true;//存在 工程结算价/最终结算价 等等
                    }
                    break;
            }
        }
        doubles[0]=doubles[1]+doubles[2]+doubles[3]+doubles[4]+doubles[5]+doubles[6]-minus+addcount;//默认竣工结算比对金额 默认为不减去发包人
//        getFlag = false;//默认 变量为 flase 传给 其他方法进行判断
        if (flag){//如果为true 说明存在 工程结算价
            doubles[0] = doubles[0]+ minus - addcount;//还原
        }
        if ((jgjeCount-5.0)>=doubles[0]||(jgjeCount+5.0)<=doubles[0]){
            //减去发包人
            doubles[0]=doubles[1]+doubles[2]+doubles[3]+doubles[4]+doubles[5]+doubles[6]-doubles[7]-minus+addcount;
//            getFlag = true;//改变 变量为 flase 传给 其他方法进行判断
        }
        if (flag){//如果为true 说明存在 工程结算价
            doubles[0] = doubles[0]+ minus - addcount;
        }
        return doubles[0];//竣工结算价  比对金额
    }
    /**
     * 工程结算价 校验
     * @param settlements 《工程项目结算汇总表》 集合
     * @return double 计算工程结算价核对金额
     */
    public static double getGcComparison(List<Settlement> settlements){
        double fbrMoney = 0.0;//发包人费 存储
        String name="";
        double money=0.0;
        double minus = 0.0;
        double addcount = 0.0;
        double count = 0.0;
        for (Settlement settlement:settlements){
            name = settlement.getEntryName();
            //判断  兼容
            if (name.equals(BDZ_TBNAME)){//投标报价
                name=BashInfo.JS_JGJS;//竣工结算价合计
            }
            if(name.equals(BDZ_TBRNAME)){//投标人采购设备费
                name=BashInfo.JS_CBRF;//承包人采购设备费
            }
            if (name.equals(BDZ_ZBRNAME)){//招标人采购材料费
                name=BashInfo.JS_FBRF;//发包人采购材料费
            }
//            if (name.equals(BDZ_TBNAME)){//投标报价
//                name=BashInfo.JS_JGJS;//竣工结算价合计
//            }
            //如果包含 “扣”  “减” “下浮”
            if (name.contains(RESON_KYJ)||name.contains(RESON_XF)||name.contains(RESON_KYJ1)){
                if (!name.equals(RESON_XFHZJ)){//如果 不等于下浮造价
                    name = RESON_KYJ;//赋值name：“扣”
                }
            }
            if (name.equals(RESON_ZZJS)){//工程结算价/最终结算价 等等 兼容
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_ZZFC)){//工程结算价/最终结算价 等等 兼容
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_ZGTB)){//工程结算价/最终结算价 等等 兼容
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_XFHZJ)){//工程结算价/最终结算价 等等 兼容
                name = BashInfo.JS_GCJS;
            }
            money =settlement.getMoney();
            switch (name) {
                case BashInfo.JS_FBRF://发包人采购材料费
                    fbrMoney+=money;//估值给fbrMoney
                    break;
                case RESON_KYJ://扣
                    minus += money; //获取减去的金额
                    break;
                default:
                    //如果不等于 竣工结算价 和工程结算价
                    if (!name.equals(BashInfo.JS_JGJS)&&!name.equals(BashInfo.JS_GCJS)){
                        addcount+=money; //金额相加
                    }
                    break;
            }
        }
        Boolean jgjsDeveloper = getJgjsDeveloper(settlements);
        if (jgjsDeveloper){//为true时 减去发包人费
            count =addcount-fbrMoney-minus;
        }else {//否则
            count=addcount-minus;//不减去
        }
        return count; //返回 工程结算价/最终结算价 等等  比对金额
    }
    /**
     * 前台显示提示数据匹配：架空线路
     * @param settlementList 数据库  集合
     * @return 数据库匹配后返回  集合
     */
    public static List<Settlement> getSelectSettlement(List<Settlement> settlementList){
        boolean flag = false;//定义开关
        String key="";//名称
        String reason="";//拼接字符串 提示信息 返会给前台
        for(Settlement settlement:settlementList){
            key = settlement.getEntryName();
            if (key.equals(BDZ_TBRNAME)){//投标人采购设备费
                flag=true;//打开开关
                key = BashInfo.JS_CBRF;//key="承包人采购设备费"
            }
            if (key.equals(BDZ_ZBRNAME)){//招标人采购材料费
                flag=true;
                key=BashInfo.JS_FBRF;//"发包人采购材料费"
            }
            if (key.equals(BDZ_TBNAME)){//投标报价
                flag=true;
                key = BashInfo.JS_JGJS;//"竣工结算价合计"
            }
            if (key.equals(RESON_ZZJS)){//最终结算价
                key = BashInfo.GCJS;//工程结算价
            }
            switch (key){
                case BashInfo.JS_FBFX://"分部分项工程费
                    //得到提示分部分项字符串
                    reason = getFbfxJoint(settlement);//提示字符串
                    settlement.setReason(reason);//存放到对象当中
                    break;
                case  BashInfo.JS_CBRF://承包人采购设备费
                    if(flag){ //如果为true 为 投标人采购设备费
                        settlement.setEntryName(BDZ_TBRNAME);//（可去掉）
                        reason = getJoint(BDZ_TBRCG,BDZ_TBRCG1,settlement);//提示字符串
                        flag= false; //默认关闭
                    }else {
                        reason = getJoint(RESON_CBRF,RESON_CBRF1,settlement);//提示字符串
                    }
                    settlement.setReason(reason);//存放到对象当中
                    break;
                case BashInfo.JS_CSXM://措施项目费
                    reason =getCsfJoint(RESON_CSXM,settlement);//提示字符串
                    settlement.setReason(reason);//存放到对象当中
                    break;
                case BashInfo.JS_QTXM://其他项目费
                    reason=getJoint(RESON_QTXM,RESON_QTXM1,settlement);//提示字符串
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_GF://"规费"
                    reason=getJoint(RESON_GF,RESON_GF1,settlement);//提示字符串
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_SJ://"税金"
                    reason=RESON_SJ;
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_FBRF://发包人采购材料费
                    if(flag){
                        settlement.setEntryName(BashInfo.JS_FBRF);
                        reason=getJoint(BDZ_FBRF,RESON_FBRF2,settlement);//提示字符串
                        flag= false; //默认关闭
                    }else {
                        reason=getJoint(RESON_FBRF,RESON_FBRF1,settlement);//提示字符串
                    }
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_JGJS:
                    if(flag){
                        settlement.setEntryName(BDZ_TBNAME);
                        reason = getJgJoint(BDZ_TBBJ,settlement,settlementList);//提示字符串
                        flag = false;
                    }else {
                        reason = getJgJoint(RESON_JGJS,settlement,settlementList);//提示字符串
                    }
                    settlement.setReason(reason);
                    break;
                case BashInfo.GCJS:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);//提示字符串
                    settlement.setReason(reason);
                    break;
                case RESON_ZZFC:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);//提示字符串
                    settlement.setReason(reason);
                    break;
                case RESON_ZGTB:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);//提示字符串
                    settlement.setReason(reason);
                    break;
                case RESON_XFHZJ:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);//提示字符串
                    settlement.setReason(reason);
                    break;
            }
        }
        return settlementList;
    }
    /**
     * 前台显示 提示数据匹配：电缆
     * @param settlementList 数据库  集合
     * @return 数据库匹配后返回  集合
     */
    public static List<Settlement> getSelectDlSettlement(List<Settlement> settlementList){
        boolean flag = false;//定义开关
        String key="";
        String reason="";
        for(Settlement settlement:settlementList){
            key = settlement.getEntryName();
            if (key.equals(BDZ_TBRNAME)){//"投标人采购设备费"
                flag=true;
                key = BashInfo.JS_CBRF;//"承包人采购设备费"
            }
            if (key.equals(BDZ_ZBRNAME)){//"招标人采购材料费"
                flag=true;
                key=BashInfo.JS_FBRF;//"发包人采购材料费"
            }
            if (key.equals(BDZ_TBNAME)){//投标报价
                flag=true;
                key = BashInfo.JS_JGJS;//"竣工结算价合计"
            }
            if (key.equals(RESON_ZZJS)){// "最终结算价"
                key = BashInfo.GCJS;//"工程结算价"
            }
            switch (key){
                case BashInfo.JS_FBFX:// "分部分项工程费"
                    reason = getDJoint(settlement,DLBDZ_FBFX1);//提示字符串
                    settlement.setReason(reason);
                    break;
                case  BashInfo.JS_CBRF://"承包人采购设备费
                    if(flag){
                        settlement.setEntryName(BDZ_TBRNAME);
                        reason = getJoint(BDZ_TBRCG,BDZ_TBRCG1,settlement);//提示字符串
                        flag= false; //默认关闭
                    }else {
                        reason = getJoint(RESON_CBRF,RESON_CBRF1,settlement);//提示字符串
                    }
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_CSXM:
                    reason =getCsfJoint(RESON_CSXM,settlement);//提示字符串
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_QTXM:
                    reason=getJoint(RESON_QTXM,RESON_QTXM1,settlement);//提示字符串
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_GF:
                    reason=getJoint(RESON_GF,RESON_GF1,settlement);//提示字符串
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_SJ:
                    reason=RESON_SJ;
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_FBRF:
                    if(flag){
                        settlement.setEntryName(BDZ_ZBRNAME);
                        reason=getDlJoint(BDZ_FBRF,BDZ_FBRF1,BDZ_FBRF2,settlement);//提示字符串
                        flag = false;
                    }else {
                        reason=getDlJoint(RESON_FBRF,RESON_DLFBRF1,RESON_DLFBRF2,settlement);//提示字符串
                    }
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_JGJS:
                    if(flag){
                        settlement.setEntryName(BDZ_TBNAME);
                        reason = getJgJoint(BDZ_TBBJ,settlement,settlementList);//提示字符串
                        flag =false;
                    }else {
                        reason = getJgJoint(RESON_JGJS,settlement,settlementList);//提示字符串
                    }
                    settlement.setReason(reason);
                    break;
                case BashInfo.GCJS:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);//提示字符串
                    settlement.setReason(reason);
                    break;
                case RESON_ZZFC:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);//提示字符串
                    settlement.setReason(reason);
                    break;
                case RESON_ZGTB:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);//提示字符串
                    settlement.setReason(reason);
                    break;
                case RESON_XFHZJ:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);//提示字符串
                    settlement.setReason(reason);
                    break;
            }
        }
        return settlementList;
    }

    /**
     * 前台显示提示数据匹配：变电站
     * @param settlementList 数据库获取所有数据
     * @return 数据库匹配后返回  集合
     */
    public static List<Settlement> getSelectBdzSettlement(List<Settlement> settlementList){
        boolean flag = false;//定义开关
        String key=""; //匹配字段
        String reason=""; //提示 字段
        for(Settlement settlement:settlementList){
            key = settlement.getEntryName();
            //字段 匹配
            if (key.equals(BashInfo.JS_CBRF)){
                flag=true;
                key = BDZ_TBRNAME;
            }
            if (key.equals(BashInfo.JS_FBRF)){
                flag=true;
                key=BDZ_ZBRNAME;
            }
            if (key.equals(BashInfo.JS_JGJS)){
                flag=true;
                key = BDZ_TBNAME;
            }
            switch (key){
                case BashInfo.JS_FBFX:
                    reason = getDJoint(settlement,DLBDZ_FBFX2);
                    settlement.setReason(reason);
                    break;
                case  BDZ_TBRNAME:
                    if(flag){ //如果为true 变电站字段为工程竣工
                        settlement.setEntryName(BashInfo.JS_CBRF);
                        reason = getJoint(RESON_CBRF,RESON_CBRF1,settlement);
                        flag= false; //默认关闭
                    }else {
                        reason = getJoint(BDZ_TBRCG,BDZ_TBRCG1,settlement);
                    }
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_CSXM:
                    reason =getCsfJoint(BDZ_CSF,settlement);
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_QTXM:
                    reason=getJoint(BDZ_QTXM,BDZ_QTXM1,settlement);
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_GF:
                    reason=getJoint(BDZ_GF,RESON_GF1,settlement);
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_SJ:
                    reason=BDZ_SJ;
                    settlement.setReason(reason);
                    break;
                case SettementUtil.BDZ_ZBRNAME:
                    if(flag){
                        settlement.setEntryName(BashInfo.JS_FBRF);
                        reason=getDlJoint(RESON_FBRF,RESON_DLFBRF1,RESON_DLFBRF2,settlement);
                        flag= false; //默认关闭
                    }else {
                        reason=getDlJoint(BDZ_FBRF,BDZ_FBRF1,BDZ_FBRF2,settlement);
                    }
                    settlement.setReason(reason);
                    break;
                case SettementUtil.BDZ_TBNAME:
                    if(flag){
                        settlement.setEntryName(BashInfo.JS_JGJS);
                        reason = getJgJoint(RESON_JGJS,settlement,settlementList);
                        flag= false; //默认关闭
                    }else {
                        reason = getJgJoint(BDZ_TBBJ,settlement,settlementList);
                    }
                    settlement.setReason(reason);
                    break;
                case BashInfo.GCJS:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);
                    settlement.setReason(reason);
                    break;
                case RESON_ZZFC:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);
                    settlement.setReason(reason);
                    break;
                case RESON_ZZJS:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);
                    settlement.setReason(reason);
                    break;
                case RESON_ZGTB:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);
                    settlement.setReason(reason);
                    break;
                case RESON_XFHZJ:
                    reason=getJshzJoint(RESON_GCJS,settlement,settlementList);
                    settlement.setReason(reason);
                    break;
            }
        }
        return settlementList;
    }
    /**
     * 架空项目 分部分项提示
     * @param settlement bean
     * @return String reason提示字符串
     */
    public static String getFbfxJoint(Settlement settlement){
        String reason="";//提示字符串
        String[] amout=settlement.getTheAmount().split(",");//数据库字段theAmount（该字段存放的金额）截取为数组
        //替换常量 中的xxx
        String reason1=SettementUtil.RESON_FBFX1.replace("xxx",String.valueOf(nf.format(settlement.getMoney())))+SettementUtil.RESON_FBFX2.replace("xxx",amout[0]);
        String reason2=SettementUtil.RESON_FBFX1.replace("xxx",String.valueOf(nf.format(settlement.getMoney())))+SettementUtil.RESON_FBFX3.replace("xxx",amout[1]);
        String status =settlement.getStatus();//获取状态
        if(status.equals("0")){ //如果为0
            //字符串加上 “金额一致” 并且 得到最总的分部分项提示字符串。
            reason=reason1+SettementUtil.RESON_TRUE+","+","+","+reason2+SettementUtil.RESON_TRUE;
        }
        if(status.equals("1")){//如果为“1”，金额不一致 进行判断  哪些金额一致/不一致
            double money = settlement.getMoney();
            double moneyComparison1=money+5.0;//范围金额+5.0元
            double moneyComparison2=money-5.0;//范围金额-5.0元
            double amout1 = Double.valueOf(amout[0]);
            double amout2 = Double.valueOf(amout[1]);
            if (amout1>=moneyComparison1||amout1<=moneyComparison2){
                if (amout2>=moneyComparison1||amout2<=moneyComparison2){
                    reason=reason1+SettementUtil.RESON_FLASE+","+","+","+reason2+SettementUtil.RESON_FLASE;
                }
                if(amout2<=moneyComparison1&&amout2>=moneyComparison2){
                    reason=reason1+SettementUtil.RESON_FLASE+","+","+","+reason2+SettementUtil.RESON_TRUE;
                }

            }
            if (amout2>=moneyComparison1||amout2<=moneyComparison2){
                if(amout1<=moneyComparison1&&amout1>=moneyComparison2){
                    reason=reason1+SettementUtil.RESON_TRUE+","+","+","+reason2+SettementUtil.RESON_FLASE;
                }
            }
        }
        return reason; //最终分部分项提示信息
    }
    /**
     * 获取 电缆/变电站 分部分项  reason 值
     * @param settlement bean
     * @param tips 常量数组
     * @return reason
     */
    public static String getDJoint(Settlement settlement,String[] tips){
        String reason=""; //原因
        String[] amout=settlement.getTheAmount().split(","); //分部分项比对金额的字符串截取成数组
        String reason1=tips[0].replace("xxx",String.valueOf(nf.format(settlement.getMoney())))
                +tips[1].replace("xxx",amout[2])
                +tips[2].replace("xxx",amout[3])
                +tips[3].replace("xxx",amout[0]);//提示字符串返回给前端
        String reason2=tips[0].replace("xxx",String.valueOf(nf.format(settlement.getMoney())))
                +tips[4].replace("xxx",amout[4])
                +tips[5].replace("xxx",amout[5])
                +tips[6].replace("xxx",amout[1]);//提示字符串返回给前端
        String status =settlement.getStatus();//获取状态
        if(status.equals("0")){ //如果为 0 为一致
            reason=reason1+SettementUtil.RESON_TRUE+","+","+","+reason2+SettementUtil.RESON_TRUE;//拼接上“金额一致”
        }
        if(status.equals("1")){//如果为1，判断哪里不一致
            double money = settlement.getMoney();
            double amout1 = Double.valueOf(amout[0]);
            double amout2 = Double.valueOf(amout[1]);
            double moneyComparison1=money+5.0;//范围金额+5.0元
            double moneyComparison2=money-5.0;//范围金额-5.0元
            //判断 不一致 地方 拼接不同常量
            if (amout1>=moneyComparison1||amout1<=moneyComparison2){
                if (amout2>=moneyComparison1||amout2<=moneyComparison2){
                    reason=reason1+SettementUtil.RESON_FLASE+","+","+","+reason2+SettementUtil.RESON_FLASE;
                }
                if(amout2<=moneyComparison1&&amout2>=moneyComparison2){
                    reason=reason1+SettementUtil.RESON_FLASE+","+","+","+reason2+SettementUtil.RESON_TRUE;
                }

            }
            if (amout2>=moneyComparison1||amout2<=moneyComparison2){
                if(amout1<=moneyComparison1&&amout1>=moneyComparison2){
                    reason=reason1+SettementUtil.RESON_TRUE+","+","+","+reason2+SettementUtil.RESON_FLASE;
                }
            }
        }
        return reason;
    }

    /**
     *  规费/其他费 等 计算 数据 常量匹配
     * @param constant1   匹配的常量one
     * @param constant2   匹配的常量two
     * @param settlement  Settlement 对象
     * @return Settlement reason 属性 赋值
     */
    public static String getJoint(String constant1,String constant2,Settlement settlement){
        String reason="";//提示字符串
        String status=settlement.getStatus();//获取状态
        reason=constant1.replace("xxx",String.valueOf(nf.format(settlement.getMoney())))
                +constant2.replace("xxx",settlement.getTheAmount());//常量拼接
        if (status.equals("0")){ //如果为0
            reason+=SettementUtil.RESON_TRUE; //拼接上“金额一致”
        }else {
            reason+=SettementUtil.RESON_FLASE; //拼接上“金额不一致”
        }
        return reason;
    }

    /**
     * 措施费对比
     * @param csxm  措施费常量
     * @param settlement bean
     * @return reason
     */
    public static String getCsfJoint(String csxm,Settlement settlement){
        String status =settlement.getStatus();//获取状态
        String[] amout=settlement.getTheAmount().split(",");//获取存入的金额比对字符串，截取为数组
        String reason=csxm.replace("xxx",String.valueOf(nf.format(settlement.getMoney())))
                +RESON_CSXM1.replace("xxx",amout[0])+
                RESON_CSXM2.replace("xxx",amout[1])+
                RESON_CSXM3.replace("xxx",amout[2]);//常量拼接是金额
        if (status.equals("0")){//如果为0
            reason+=RESON_TRUE;//拼接上“金额一致”
        }else {
            reason+=RESON_FLASE;
        }
        return reason;
    }
    /**
     * 电缆/变电站 发包人采购对比
     * @param s 发包人采购 常量 s1
     * @param settlement bean
     * @return reason
     */
    public static String getDlJoint(String s,String s1,String s2,Settlement settlement){
        String reason="";//提示字符串
        String[] amout = settlement.getTheAmount().split(",");//获取存入的金额字符串，截取为数组
        String status=settlement.getStatus();//获取状态
        reason=s.replace("xxx",String.valueOf(nf.format(settlement.getMoney())))
                +s1.replace("xxx",amout[1])
                +s2.replace("xxx",amout[2])
                +RESON_JGJS8.replace("xxx",amout[0]);//拼接
        if (status.equals("0")){//判断是否一致
            reason+=SettementUtil.RESON_TRUE; //拼接 “金额一致” 字符串
        }else {
            reason+=SettementUtil.RESON_FLASE;//拼接 “金额不一致” 字符串
        }
        return reason;
    }
    /**
     * 竣工结算价合计 常量匹配
     * @param tops //常量拼接
     * @param settlement bean
     * @param  settlements  集合
     * @return string reason值
     */
    public static String getJgJoint(String tops,Settlement settlement,List<Settlement> settlements){
        String reason="";//提示字符串
        reason+=tops.replace("xxx",String.valueOf(nf.format(settlement.getMoney())));//获取存入的金额，截取为数组
        String amout=settlement.getTheAmount();
        String name = "";
        for (int i = 0; i < settlements.size(); i++) {//循环遍历list集合中的settlement对象
            name = settlements.get(i).getEntryName();
            if (name.equals(BashInfo.JS_JGJS)||//循环到竣工结算/投标报价 跳出循环
                    name.equals(BDZ_TBNAME)){
                reason+=RESON_JGJS8.replace("xxx",amout);//字符串拼接
                if (settlement.getStatus().equals("0")){//判断是否一致
                    reason+=SettementUtil.RESON_TRUE;//如果一致 拼接“金额一致字符串”
                }else {
                    reason+=SettementUtil.RESON_FLASE;//如果不一致 拼接“金额一致字符串”
                }
                return reason;
            }
            //字符串替换 xxx  为指定金额
            reason += ","+settlements.get(i).getEntryName()+",<span style='font-weight: bold;'>"+nf.format(settlements.get(i).getMoney())+"</span>,";
        }
        //如果循环中为跳出，执行如下
        reason+=RESON_JGJS8.replace("xxx",amout);//拼接小计金额
        if (settlement.getStatus().equals("0")){
            reason+=SettementUtil.RESON_TRUE;
        }else {
            reason+=SettementUtil.RESON_FLASE;
        }
        return reason;
    }
    /**
     * 工程结算 提示
     * @param tops 表名 常量
     * @param settlement 对象
     * @param settlements  对象集合
     * @return String reason 提示字符串
     */
    public static String getJshzJoint(String tops,Settlement settlement,List<Settlement> settlements){
        String reason="";//提示字符串
        String name="";//名称
        reason = tops.replace("xxx",String.valueOf(nf.format(settlement.getMoney())));//给提示字符串赋予初始提示
        String amout=settlement.getTheAmount();
        for (int i = 0; i < settlements.size(); i++) {//循环遍历list集合中的settlement对象
            name = settlements.get(i).getEntryName();
            if (name.equals(BashInfo.JS_JGJS)|| name.equals(BDZ_TBNAME)){//如果 循环到 竣工结算 跳过此次循环
                continue;
            }
            //如果循环到 工程结算/.../...等 直接返回
            if (name.equals(BashInfo.JS_GCJS)|| name.equals(RESON_ZZJS)|| name.equals(RESON_ZZFC)|| name.equals(RESON_ZGTB)||
                    name.equals(RESON_XFHZJ)){
                reason+=RESON_JGJS8.replace("xxx",amout);
                if (settlement.getStatus().equals("0")){
                    reason+=SettementUtil.RESON_TRUE;
                }else {
                    reason+=SettementUtil.RESON_FLASE;
                }
                return reason;
            }
            //提示字符串 替换xxx 的值为 指定金额
            reason += ","+settlements.get(i).getEntryName()+",<span style='font-weight: bold;'>"+nf.format(settlements.get(i).getMoney())+"</span>,";
        }
        //如果循环中为跳出，则无工程结算/.../...等 执行如下
        reason+=RESON_JGJS8.replace("xxx",amout);
        if (settlement.getStatus().equals("0")){
            reason+=SettementUtil.RESON_TRUE;
        }else {
            reason+=SettementUtil.RESON_FLASE;
        }
        return reason;
    }
    /**
     *  添加获取数据到settlement 对象
     * @param settlement bean
     * @param key    当前循环到的key值
     * @param importExcel importExcel
     * @param i 当前循环到到的下标
     * @return 对象
     */
    public static Settlement getSettlement(Settlement settlement,String key,ImportExcel importExcel,int i){
        settlement.setEntryName(key);
        settlement.setMoney(importExcel.getDouble(i+1,2));
        settlement.setRemarks(importExcel.getValue(i+1,3));
        return settlement;
    }


    //判断是否减去发包人
    public static Boolean getJgjsDeveloper(List<Settlement> settlements){
        boolean flagDeveloper = false;
        double[] doubles = new double[8]; //定义数组 （可改）
        boolean flag= false; //用作判断是否存在 工程结算价/最终结算价 等等。
        String name=""; //settlement对象名称
        double money=0.0;//settlement对象金额
        double minus = 0.0;// 减去的金额合计
        double addcount = 0.0;//加上的金额合计
        double jgjeCount = 0.0;//存放竣工结算价金额
        for (Settlement settlement:settlements){
            name = settlement.getEntryName();
            money = settlement.getMoney();
            if (name.equals(BDZ_TBNAME)){//如果为投标报价
                name=BashInfo.JS_JGJS; //name=竣工结算
            }
            if(name.equals(BDZ_TBRNAME)){//如果为 投标人采购设备费
                name=BashInfo.JS_CBRF; //承包人费
            }
            if (name.equals(BDZ_ZBRNAME)){ //如果为招标人费
                name=BashInfo.JS_FBRF;//发包人采购材料费
            }
            //如果包含 “扣”  “减” “下浮”
            if (name.contains(RESON_KYJ)||name.contains(RESON_XF)||name.contains(RESON_KYJ1)){
                if (!name.equals(RESON_XFHZJ)){//如果 不等于下浮造价
                    name = RESON_KYJ; //赋值name：“扣”
                }
            }
            if (name.equals(RESON_ZZJS)){//工程结算价 兼容
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_ZZFC)){//工程结算价 兼容
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_ZGTB)){//工程结算价 兼容
                name = BashInfo.JS_GCJS;
            }
            if (name.equals(RESON_XFHZJ)){//工程结算价 兼容
                name = BashInfo.JS_GCJS;
            }
            switch (name) {
                case BashInfo.JS_FBFX://分部分项工程费
                    doubles[1]=money;
                    break;
                case BashInfo.JS_CBRF://承包人采购设备费
                    doubles[2]=money;
                    break;
                case BashInfo.JS_CSXM://措施项目费
                    doubles[3]=money;
                    break;
                case BashInfo.JS_QTXM://其他项目费
                    doubles[4]=money;
                    break;
                case BashInfo.JS_GF://规费
                    doubles[5]=money;
                    break;
                case BashInfo.JS_SJ://税金
                    doubles[6]=money;
                    break;
                case BashInfo.JS_FBRF://发包人采购材料费
                    doubles[7]=money;
                    break;
                case RESON_KYJ://扣
                    minus += money; //需要减去的金额累加
                    break;
                default: //如果以上不匹配
                    if (name.equals(BashInfo.JS_JGJS)){//如果等于 "竣工结算价合计"
                        jgjeCount=money; //存储  "竣工结算价合计" 金额
                    }else if (!name.equals(BashInfo.JS_GCJS)){ //如果不等于 工程结算价
                        addcount+=money; //需要加上的金额 累加
                    }
                    if (name.equals(BashInfo.JS_GCJS)){ //如果name为 工程结算价
                        flag=true;//存在 工程结算价/最终结算价 等等
                    }
                    break;
            }
        }
        doubles[0]=doubles[1]+doubles[2]+doubles[3]+doubles[4]+doubles[5]+doubles[6]-minus+addcount;//默认竣工结算比对金额 默认为不减去发包人

        if (flag){//如果为true 说明存在 工程结算价
            doubles[0] = doubles[0]+ minus - addcount;//还原
        }
        if ((jgjeCount-5.0)>=doubles[0]||(jgjeCount+5.0)<=doubles[0]){
            //减去发包人
            doubles[0]=doubles[1]+doubles[2]+doubles[3]+doubles[4]+doubles[5]+doubles[6]-doubles[7]-minus+addcount;
            flagDeveloper = true;//改变 变量为 flase 传给 其他方法进行判断
        }
        return flagDeveloper;
    }
}
