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.Settlement;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

public class SettementUtil {
    public static final String RESON_TRUE="&nbsp;金额<span style='color:#0000FF'>&nbsp;一致。</span>";
    public static final String RESON_FLASE="&nbsp;金额<span style='color:#FF0000'>&nbsp;不一致。</span>";
    /*
        分布分项比对
     */
    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 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 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 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 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 RESON_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_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 RESON_JGJS="《工程项目竣工结算汇总表》中“竣工结算价合计金额”为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_JGJS1="&nbsp;分部分项工程费为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_JGJS2="&nbsp;承包人采购设备费为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_JGJS3="&nbsp;措施项目费为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_JGJS4="&nbsp;其他项目费为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_JGJS5="&nbsp;规费为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_JGJS6="&nbsp;税金为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_JGJS7="&nbsp;发包人材料费为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_JGJS8="&nbsp;汇总金额为<span style='font-weight: bold;'>xxx</span>元,";
    /*
        增补税率差额
     */
    public static final String RESON_BZZS="补增值税税率调整差额";
    public static final String RESON_KJJG="扣减甲供材超供材料费";
    /*
       工程结算
    */
    public static final String RESON_GCJS="《工程项目竣工结算汇总表》中“工程结算价”为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_GCJS1="&nbsp;竣工结算家合计为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_GCJS2="&nbsp;补增值税税率调整差额为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_GCJS3="&nbsp;扣减甲供材超供材料费为<span style='font-weight: bold;'>xxx</span>元,";
    public static final String RESON_GCJS4="&nbsp;汇总金额为<span style='font-weight: bold;'>xxx</span>元,";

    /**
     * 查找架空匹配
     */
    public static List<Settlement> getSelectSettlement(List<Settlement> settlementList){
        boolean[] booleans =getJgforJoint(settlementList);
        String key="";
        String reason="";
        for(Settlement settlement:settlementList){
            key = settlement.getEntryName();
            switch (key){
                case BashInfo.JS_FBFX:
                    reason = getFbfxJoint(settlement);
                    settlement.setReason(reason);
                    break;
                case  BashInfo.JS_CBRF:
                    reason = getJoint(RESON_CBRF,RESON_CBRF1,settlement);
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_CSXM:
                    reason =getCsfJoint(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:
                    reason=getJoint(RESON_FBRF,RESON_FBRF1,settlement);
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_JGJS:
                    reason = getJgJoint(settlement,booleans);
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_BZZS:
                    reason=RESON_BZZS;
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_KJJG:
                    reason=RESON_BZZS;
                    settlement.setReason(reason);
                    break;
                case BashInfo.GCJS:
                    reason=getJshzJoint(settlement,booleans);
                    settlement.setReason(reason);
                    break;
            }
        }
        return settlementList;
    }

    /**
     * 获取工程结算价
     */
    public static List<Settlement> getComparison(ImportExcel importExcel){
        Settlement settlement;
        List<Settlement> settlementList = new ArrayList<Settlement>();
        int lastDataRowNum =  importExcel.getLastDataRowNum();
        String key = "";//获取结算名称
        for (int i = 0; i < lastDataRowNum; i++) {
            settlement=new Settlement();
            key =  importExcel.getValue(i+1,1);
            if(key.contains(BashInfo.JS_SJ)){
                key=BashInfo.JS_SJ;
            }
            switch (key){
                case BashInfo.JS_FBFX:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
                case BashInfo.JS_CBRF:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
                case BashInfo.JS_CSXM:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
                case BashInfo.JS_QTXM:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
                case BashInfo.JS_GF:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
                case BashInfo.JS_SJ:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
                case BashInfo.JS_FBRF:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
                case BashInfo.JS_JGJS:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
                case BashInfo.JS_BZZS:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
                case BashInfo.JS_KJJG:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
                case BashInfo.JS_GCJS:
                    settlement.setEntryName(key);
                    settlement.setMoney(importExcel.getDouble(i+1,2));
                    settlement.setRemarks(importExcel.getValue(i+1,3));
                    settlementList.add(settlement);
                    break;
            }
        }
        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;//获取当前汇总表金额
        Settlement settlement;//对象
        for (int i = 0; i < settlements.size(); i++) {
            settlement=settlements.get(i);
            name=settlement.getEntryName();
            money=settlement.getMoney();
            settlement.setStatus("1");
            switch (name){
                case BashInfo.JS_FBFX:
                    if (money==builtTotal&&money==divisiontotal[0]){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(builtTotal+","+divisiontotal[0]));
                    break;
                case  BashInfo.JS_CBRF:
                    if(money==cbperson){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(cbperson));
                    break;
                case BashInfo.JS_CSXM:
                    if (money==wordtotal){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(wordtotal1+","+wordtotal2+","+wordtotal));
                    break;
                case BashInfo.JS_QTXM:
                    if(money==otherTotal){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(otherTotal));
                    break;
                case BashInfo.JS_GF:
                    if (money==feescount){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(feescount));
                    break;
                case BashInfo.JS_SJ:
                    settlement.setStatus("2");
                    settlement.setTheAmount(String.valueOf(money));
                    break;
                case BashInfo.JS_FBRF:
                    if(money==divisiontotal[1]){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(divisiontotal[1]));
                    break;
                case BashInfo.JS_JGJS:
                    double[] jgComparison = getJgjsComparison(settlements);
                    if (money==jgComparison[0]){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(StringUtils.join(jgComparison,','));
                    break;
                case BashInfo.JS_BZZS:
                    settlement.setStatus("2");
                    settlement.setTheAmount(String.valueOf(money));
                    break;
                case BashInfo.JS_KJJG:
                    settlement.setStatus("2");
                    settlement.setTheAmount(String.valueOf(money));
                    break;
                case BashInfo.JS_GCJS:
                    double[] gcComparison =getGcComparison(settlements);
                    if (money==gcComparison[0]){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(StringUtils.join(gcComparison,','));
                    break;
            }
        }
        return settlements;
    }
    /*
        计算与竣工结算价合计比对结果
     */
    public static double[] getJgjsComparison(List<Settlement> settlements){
        double[] doubles = new double[8];
        String name;
        double money=0;
        for (Settlement settlement:settlements){
            name = settlement.getEntryName();
            money =settlement.getMoney();
            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;
            }
        }
        doubles[0]=doubles[1]+doubles[2]+doubles[3]+doubles[4]+doubles[5]+doubles[6]-doubles[7];
        return doubles;
    }
    /*
        工程结算价比对结果
     */
    public static double[] getGcComparison(List<Settlement> settlements){
        double[] doubles=new double[4];
        String name;
        double money=0;
        for (Settlement settlement:settlements){
            name = settlement.getEntryName();
            money =settlement.getMoney();
            switch (name) {
                case BashInfo.JS_JGJS://竣工结算
                    doubles[1]=money;
                    break;
                case BashInfo.JS_BZZS://补增值税
                    doubles[2]=money;
                    break;
                case BashInfo.JS_KJJG://扣减
                    doubles[3]=money;
                    break;
            }
        }
        doubles[0]=doubles[1]+doubles[2]-doubles[3];
        return doubles;
    }
    /*
        常量拼接
     */
    public static String getJoint(String constant1,String constant2,Settlement settlement){
        String reason="";
        String status=settlement.getStatus();
        reason=constant1.replace("xxx",String.valueOf(settlement.getMoney()))
                +"<br>"+constant2.replace("xxx",settlement.getTheAmount());
        if (status.equals("0")){
            reason+="<br>"+SettementUtil.RESON_TRUE;
        }else {
            reason+="<br>"+SettementUtil.RESON_FLASE;
        }
        return reason;
    }
    /*
        竣工结算拼接
     */
    public static String getJgJoint(Settlement settlement,boolean[] booleans){
        String reason="";
        String[] amout=settlement.getTheAmount().split(",");
        reason+=RESON_JGJS.replace("xxx",String.valueOf(settlement.getMoney()));
        if (booleans[1]){
            reason+="<br>"+RESON_JGJS1.replace("xxx",amout[1]);
        }
        if (booleans[2]){
            reason+="<br>"+RESON_JGJS2.replace("xxx",amout[2]);
        }
        if (booleans[3]){
            reason+="<br>"+RESON_JGJS3.replace("xxx",amout[3]);
        }
        if (booleans[4]){
            reason+="<br>"+RESON_JGJS4.replace("xxx",amout[4]);
        }
        if (booleans[5]){
            reason+="<br>"+RESON_JGJS5.replace("xxx",amout[5]);
        }
        if (booleans[6]){
            reason+="<br>"+RESON_JGJS6.replace("xxx",amout[6]);
        }
        if (booleans[7]){
            reason+="<br>"+RESON_JGJS7.replace("xxx",amout[7]);
        }
        reason+="<br>"+RESON_JGJS8.replace("xxx",amout[0]);
        if (settlement.getStatus().equals("0")){
            reason+="<br>"+SettementUtil.RESON_TRUE;
        }else {
            reason+="<br>"+SettementUtil.RESON_FLASE;
        }
        return reason;
    }
    /*
        架空分布分项工程费对比
     */
    public static String getFbfxJoint(Settlement settlement){
        String reason="";
        String[] amout=settlement.getTheAmount().split(",");
        String reason1=SettementUtil.RESON_FBFX1.replace("xxx",String.valueOf(settlement.getMoney()))+"<br>"+SettementUtil.RESON_FBFX2.replace("xxx",amout[0]);
        String reason2=SettementUtil.RESON_FBFX2.replace("xxx",amout[0])+"<br>"+SettementUtil.RESON_FBFX3.replace("xxx",amout[1]);
        String status =settlement.getStatus();
        if(status.equals("0")){
            reason=reason1+"<br>"+SettementUtil.RESON_TRUE+"<br>"+reason2+"<br>"+SettementUtil.RESON_TRUE;
        }
        if(status.equals("1")){
            double money = settlement.getMoney();
            double amout1 = Double.valueOf(amout[0]);
            double amout2 = Double.valueOf(amout[1]);
            if(money!=amout1&&amout1!=amout2){
                reason=reason1+"<br>"+SettementUtil.RESON_FLASE+"<br>"+reason2+"<br>"+SettementUtil.RESON_FLASE;
            }
            if(amout1!=amout2&&money==amout1){
                reason=reason1+"<br>"+SettementUtil.RESON_TRUE+"<br>"+reason2+"<br>"+SettementUtil.RESON_FLASE;
            }
            if (money!=amout1&&amout1==amout2){
                reason=reason1+"<br>"+SettementUtil.RESON_TRUE+"<br>"+reason2+"<br>"+SettementUtil.RESON_TRUE;
            }
        }
        return reason;
    }
    /*
        措施费对比
     */
    public static String getCsfJoint(Settlement settlement){
        String status =settlement.getStatus();
        String[] amout=settlement.getTheAmount().split(",");
        String reason=RESON_CSXM.replace("xxx",String.valueOf(settlement.getMoney()))
                +"<br>"+RESON_CSXM1.replace("xxx",amout[0])+
                "<br>"+RESON_CSXM2.replace("xxx",amout[1])+
                "<br>"+RESON_CSXM3.replace("xxx",amout[2]);
        if (status.equals("0")){
            reason+="<br>"+RESON_TRUE;
        }else {
            reason+="<br>"+RESON_FLASE;
        }
        return reason;
    }
    /*
        结算汇总拼接
     */
    public static String getJshzJoint(Settlement settlement,boolean[] booleans){
        String reason="";
        String[] amout=settlement.getTheAmount().split(",");
        reason+=RESON_GCJS.replace("xxx",String.valueOf(settlement.getMoney()));
        if (booleans[8]){
            reason+="<br>"+RESON_GCJS1.replace("xxx",amout[1]);
        }
        if (booleans[9]){
            reason+="<br>"+RESON_GCJS2.replace("xxx",amout[2]);
        }
        if (booleans[10]) {
            reason += "<br>" + RESON_GCJS3.replace("xxx", amout[3]);
        }
        reason+="<br>"+RESON_GCJS4.replace("xxx",amout[0]);
        if (settlement.getStatus().equals("0")){
            reason+="<br>"+SettementUtil.RESON_TRUE;
        }else {
            reason+="<br>"+SettementUtil.RESON_FLASE;
        }
        return reason;
    }
    /*
        获取《工程竣工对比是否存在》
     */
    public static boolean[] getJgforJoint(List<Settlement> settlements){
        String key;
        boolean[] booleans = new boolean[11];
        for (int i = 0; i < booleans.length; i++) {
            booleans[i]=false;
        }
        for (int i = 0; i < settlements.size(); i++) {
            key =  settlements.get(i).getEntryName();
            switch (key){
                case BashInfo.JS_FBFX:
                    booleans[1]=true;
                    break;
                case  BashInfo.JS_CBRF:
                    booleans[2]=true;
                    break;
                case BashInfo.JS_CSXM:
                    booleans[3]=true;
                    break;
                case BashInfo.JS_QTXM:
                    booleans[4]=true;
                    break;
                case BashInfo.JS_GF:
                    booleans[5]=true;
                    break;
                case BashInfo.JS_SJ:
                    booleans[6]=true;
                    break;
                case BashInfo.JS_FBRF:
                    booleans[7]=true;
                    break;
                case BashInfo.JS_JGJS://竣工结算
                    booleans[8]=true;
                    break;
                case BashInfo.JS_BZZS://补增值税
                    booleans[9]=true;
                    break;
                case BashInfo.JS_KJJG://扣减
                    booleans[10]=true;
                    break;
            }
        }
        return booleans;
    }

    /*
//        电缆校验
//     */
    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;//获取当前汇总表金额
        Settlement settlement;//对象
        for (int i = 0; i < settlements.size(); i++) {
            settlement=settlements.get(i);
            name=settlement.getEntryName();
            money=settlement.getMoney();
            settlement.setStatus("1");
            switch (name){
                case BashInfo.JS_FBFX:
                    double division=divisiontotal[0]+divisiontotal[2];
                    double built = builtTotal[0]+builtTotal[1];
                    if (money==built&&money==division){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(built+","+division+","+builtTotal[0]+","+builtTotal[1]+","+divisiontotal[0]+","+divisiontotal[2]));
                    break;
                case  BashInfo.JS_CBRF:
                    if(money==cbperson){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(cbperson));
                    break;
                case BashInfo.JS_CSXM:
                    if (money==wordtotal){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(wordtotal1+","+wordtotal2+","+wordtotal));
                    break;
                case BashInfo.JS_QTXM:
                    if(money==otherTotal){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(otherTotal));
                    break;
                case BashInfo.JS_GF:
                    if (money==feescount){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(feescount));
                    break;
                case BashInfo.JS_SJ:
                    settlement.setStatus("2");
                    settlement.setTheAmount(String.valueOf(money));
                    break;
                case BashInfo.JS_FBRF:
                    double divisionFbr =divisiontotal[1]+divisiontotal[3];
                    if(money==divisiontotal[1]){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(String.valueOf(divisionFbr+","+divisiontotal[1]+","+divisiontotal[3]));
                    break;
                case BashInfo.JS_JGJS:
                    double[] jgComparison = getJgjsComparison(settlements);
                    if (money==jgComparison[0]){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(StringUtils.join(jgComparison,','));
                    break;
                case BashInfo.JS_BZZS:
                    settlement.setStatus("2");
                    settlement.setTheAmount(String.valueOf(money));
                    break;
                case BashInfo.JS_KJJG:
                    settlement.setStatus("2");
                    settlement.setTheAmount(String.valueOf(money));
                    break;
                case BashInfo.JS_GCJS:
                    double[] gcComparison =getGcComparison(settlements);
                    if (money==gcComparison[0]){
                        settlement.setStatus("0");
                    }
                    settlement.setTheAmount(StringUtils.join(gcComparison,','));
                    break;
            }
        }
        return settlements;
    }
    /**
     * 查找电缆匹配
     */
    public static List<Settlement> getSelectDlSettlement(List<Settlement> settlementList){
        boolean[] booleans =getJgforJoint(settlementList);
        String key="";
        String reason="";
        for(Settlement settlement:settlementList){
            key = settlement.getEntryName();
            switch (key){
                case BashInfo.JS_FBFX:
                    reason = getDJoint(settlement);
                    settlement.setReason(reason);
                    break;
                case  BashInfo.JS_CBRF:
                    reason = getJoint(RESON_CBRF,RESON_CBRF1,settlement);
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_CSXM:
                    reason =getCsfJoint(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:
                    reason=getDlJoint(settlement);
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_JGJS:
                    reason = getJgJoint(settlement,booleans);
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_BZZS:
                    reason=RESON_BZZS;
                    settlement.setReason(reason);
                    break;
                case BashInfo.JS_KJJG:
                    reason=RESON_BZZS;
                    settlement.setReason(reason);
                    break;
                case BashInfo.GCJS:
                    reason=getJshzJoint(settlement,booleans);
                    settlement.setReason(reason);
                    break;
            }
        }
        return settlementList;
    }
    /*
       电缆分布分项工程费对比
    */
    public static String getDJoint(Settlement settlement){
        String reason="";
        String[] amout=settlement.getTheAmount().split(",");
        String reason1=SettementUtil.RESON_FBFX1.replace("xxx",String.valueOf(settlement.getMoney()))
                +"<br>"+SettementUtil.RESON_JZFBFX.replace("xxx",amout[2])
                +"<br>"+SettementUtil.RESON_AZFBFX.replace("xxx",amout[3])
                +"<br>"+SettementUtil.RESON_GCJS4.replace("xxx",amout[0]);
        String reason2=SettementUtil.RESON_FBFX1.replace("xxx",String.valueOf(settlement.getMoney()))
                +"<br>"+SettementUtil.RESON_JZFBFX3.replace("xxx",amout[4])
                +"<br>"+SettementUtil.RESON_AZFBFX3.replace("xxx",amout[5])
                +"<br>"+SettementUtil.RESON_GCJS4.replace("xxx",amout[1]);
        String status =settlement.getStatus();
        if(status.equals("0")){
            reason=reason1+"<br>"+SettementUtil.RESON_TRUE+"<br>"+reason2+"<br>"+SettementUtil.RESON_TRUE;
        }
        if(status.equals("1")){
            double money = settlement.getMoney();
            double amout1 = Double.valueOf(amout[0]);
            double amout2 = Double.valueOf(amout[1]);
            if(money!=amout1&&amout1!=amout2){
                reason=reason1+"<br>"+SettementUtil.RESON_FLASE+"<br>"+reason2+"<br>"+SettementUtil.RESON_FLASE;
            }
            if(amout1!=amout2&&money==amout1){
                reason=reason1+"<br>"+SettementUtil.RESON_TRUE+"<br>"+reason2+"<br>"+SettementUtil.RESON_FLASE;
            }
            if (money!=amout1&&amout1==amout2){
                reason=reason1+"<br>"+SettementUtil.RESON_TRUE+"<br>"+reason2+"<br>"+SettementUtil.RESON_TRUE;
            }
        }
        return reason;
    }
    /*
        电缆发包人对比
     */
    public static String getDlJoint(Settlement settlement){
        String reason="";
        String[] amout = settlement.getTheAmount().split(",");
        String status=settlement.getStatus();
        reason=RESON_FBRF.replace("xxx",String.valueOf(settlement.getMoney()))
                +"<br>"+RESON_DLFBRF1.replace("xxx",amout[1])
                +"<br>"+RESON_DLFBRF2.replace("xxx",amout[2])
                +"<br>"+RESON_GCJS4.replace("xxx",amout[0]);
        if (status.equals("0")){
            reason+="<br>"+SettementUtil.RESON_TRUE;
        }else {
            reason+="<br>"+SettementUtil.RESON_FLASE;
        }
        return reason;
    }
}
