package io.renren.modules.app.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import io.renren.modules.app.entity.HPzEntity;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.modules.app.dao.YeFseDao;
import io.renren.modules.app.entity.HKmEntity;
import io.renren.modules.app.entity.HKmlbEntity;
import io.renren.modules.app.entity.YeFseEntity;
import io.renren.modules.app.service.YeFseService;

@Service("yeFseService")
public class YeFseServiceImpl extends ServiceImpl<YeFseDao, YeFseEntity> implements YeFseService {

	@Override
	public List<HPzEntity> selectYeFseByPage(HPzEntity hPzEntity) {
		List<HPzEntity> list=new ArrayList<HPzEntity>();
		List<HPzEntity> list2=new ArrayList<HPzEntity>();
		List<HKmEntity> listkm=baseMapper.selectkm(hPzEntity);
		if("0001".equals(hPzEntity.getZtbm())){
			list2 = baseMapper.yeFseSelect_1(hPzEntity);//查询全部级别号的科目数据
			for(HKmEntity k:listkm){
					HPzEntity p1=new HPzEntity();
					p1.setKmdm(k.getKm());
					p1.setKmmc(k.getKmmc());
					p1.setKmsx(k.getKmsx());
					p1.setZjqcye(0.0);
					p1.setZdqcye(0.0);
					p1.setZjfje(0.0);
					p1.setZdfje(0.0);
					p1.setJqmye(0.0);
					p1.setDqmye(0.0);
					p1.setJbh(k.getJbh());
					p1.setKmlbbm(k.getKmlbbm());
					list.add(p1);
			}
			for(HPzEntity p2:list2){
				String kmdm=p2.getKmdm();
				for(HPzEntity p3:list){
					if(p2.getKmdm().equals(p3.getKmdm())){
						p3.setKmdm(p2.getKmdm());
						p3.setKmmc(p2.getKmmc());
						p3.setKmsx(p2.getKmsx());
						p3.setZjqcye(p2.getZjqcye());
						p3.setZdqcye(p2.getZdqcye());
						p3.setZjfje(p2.getZjfje());
						p3.setZdfje(p2.getZdfje());
						p3.setJqmye(p2.getJqmye());
						p3.setDqmye(p2.getDqmye());
						p3.setJbh(p2.getJbh());
						p3.setKmlbbm(p2.getKmlbbm());
					}
				}
			}
			
			Double sumzjqcye102 = 0.0;
			Double sumzdqcye102 = 0.0;
			Double sumzjfje102 = 0.0;
			Double sumzdfje102 = 0.0;
			Double sumjqmye102 = 0.0;
			Double sumdqmye102 = 0.0;

			Double sumzjqcye211 = 0.0;
			Double sumzdqcye211 = 0.0;
			Double sumzjfje211 = 0.0;
			Double sumzdfje211 = 0.0;
			Double sumjqmye211 = 0.0;
			Double sumdqmye211 = 0.0;

			for (int i = 0; i < list.size(); i++) {// 计算级别号为2的科目的值
				if (list.get(i).getKmdm().length() == 6&&!"110001".equals(list.get(i).getKmdm())&&!"207001".equals(list.get(i).getKmdm())) {
					list.get(i).setZjqcye(list.get(i + 1).getZjqcye() + list.get(i + 2).getZjqcye());
					list.get(i).setZdqcye(list.get(i + 1).getZdqcye() + list.get(i + 2).getZdqcye());
					list.get(i).setZjfje(list.get(i + 1).getZjfje() + list.get(i + 2).getZjfje());
					list.get(i).setZdfje(list.get(i + 1).getZdfje() + list.get(i + 2).getZdfje());
					list.get(i).setJqmye(list.get(i + 1).getJqmye() + list.get(i + 2).getJqmye());
					list.get(i).setDqmye(list.get(i + 1).getDqmye() + list.get(i + 2).getDqmye());
				} else if ("102".equals(list.get(i).getKmdm().substring(0, 3)) && list.get(i).getKmdm().length() == 9) {//累加102的最低级科目的金额之和
					sumzjqcye102 = sumzjqcye102 + list.get(i).getZjqcye();
					sumzdqcye102 = sumzdqcye102 + list.get(i).getZdqcye();
					sumzjfje102 = sumzjfje102 + list.get(i).getZjfje();
					sumzdfje102 = sumzdfje102 + list.get(i).getZdfje();
					sumjqmye102 = sumjqmye102 + list.get(i).getJqmye();
					sumdqmye102 = sumdqmye102 + list.get(i).getDqmye();
				} else if ("211".equals(list.get(i).getKmdm().substring(0, 3)) && list.get(i).getKmdm().length() == 9) {//累加211的最低级科目的金额之和
					sumzjqcye211 = sumzjqcye211 + list.get(i).getZjqcye();
					sumzdqcye211 = sumzdqcye211 + list.get(i).getZdqcye();
					sumzjfje211 = sumzjfje211 + list.get(i).getZjfje();
					sumzdfje211 = sumzdfje211 + list.get(i).getZdfje();
					sumjqmye211 = sumjqmye211 + list.get(i).getJqmye();
					sumdqmye211 = sumdqmye211 + list.get(i).getDqmye();
				}
			}

			for (int j=0;j<list.size();j++) {
				if ("102".equals(list.get(j).getKmdm())) {//计算102的科目金额和
					list.get(j).setZjqcye(sumzjqcye102);
					list.get(j).setZdqcye(sumzdqcye102);
					list.get(j).setZjfje(sumzjfje102);
					list.get(j).setZdfje(sumzdfje102);
					list.get(j).setJqmye(sumjqmye102);
					list.get(j).setDqmye(sumdqmye102);
				} else if ("211".equals(list.get(j).getKmdm())) {//计算211的科目金额和
					list.get(j).setZjqcye(sumzjqcye211);
					list.get(j).setZdqcye(sumzdqcye211);
					list.get(j).setZjfje(sumzjfje211);
					list.get(j).setZdfje(sumzdfje211);
					list.get(j).setJqmye(sumjqmye211);
					list.get(j).setDqmye(sumdqmye211);
				}else if("110".equals(list.get(j).getKmdm())){//计算110的科目金额和
					list.get(j).setZjqcye(list.get(j+1).getZjqcye());
					list.get(j).setZdqcye(list.get(j+1).getZdqcye());
					list.get(j).setZjfje(list.get(j+1).getZjfje());
					list.get(j).setZdfje(list.get(j+1).getZdfje());
					list.get(j).setJqmye(list.get(j+1).getJqmye());
					list.get(j).setDqmye(list.get(j+1).getDqmye());
				}else if("207".equals(list.get(j).getKmdm())){//计算207的科目金额和
					list.get(j).setZjqcye(list.get(j+1).getZjqcye());
					list.get(j).setZdqcye(list.get(j+1).getZdqcye());
					list.get(j).setZjfje(list.get(j+1).getZjfje());
					list.get(j).setZdfje(list.get(j+1).getZdfje());
					list.get(j).setJqmye(list.get(j+1).getJqmye());
					list.get(j).setDqmye(list.get(j+1).getDqmye());
				}
			}	
		}else if("0002".equals(hPzEntity.getZtbm())){
			Double sumzjqcye101 = 0.0;
			Double sumzdqcye101 = 0.0;
			Double sumzjfje101 = 0.0;
			Double sumzdfje101 = 0.0;
			Double sumjqmye101 = 0.0;
			Double sumdqmye101 = 0.0;
			
			Double sumzjqcye201 = 0.0;
			Double sumzdqcye201 = 0.0;
			Double sumzjfje201 = 0.0;
			Double sumzdfje201 = 0.0;
			Double sumjqmye201 = 0.0;
			Double sumdqmye201 = 0.0;
			
			Double sumzjqcye311 = 0.0;
			Double sumzdqcye311 = 0.0;
			Double sumzjfje311 = 0.0;
			Double sumzdfje311 = 0.0;
			Double sumjqmye311 = 0.0;
			Double sumdqmye311 = 0.0;
			
			Double sumzjqcye401 = 0.0;
			Double sumzdqcye401 = 0.0;
			Double sumzjfje401 = 0.0;
			Double sumzdfje401 = 0.0;
			Double sumjqmye401 = 0.0;
			Double sumdqmye401 = 0.0;
			
			Double sumzjqcye411 = 0.0;
			Double sumzdqcye411 = 0.0;
			Double sumzjfje411 = 0.0;
			Double sumzdfje411 = 0.0;
			Double sumjqmye411 = 0.0;
			Double sumdqmye411 = 0.0;
		list2 = baseMapper.yeFseSelect_1(hPzEntity);//查询全部级别号的科目数据
		for(HKmEntity k:listkm){
				HPzEntity p1=new HPzEntity();
				p1.setKmdm(k.getKm());
				p1.setKmmc(k.getKmmc());
				p1.setKmsx(k.getKmsx());
				p1.setZjqcye(0.0);
				p1.setZdqcye(0.0);
				p1.setZjfje(0.0);
				p1.setZdfje(0.0);
				p1.setJqmye(0.0);
				p1.setDqmye(0.0);
				p1.setJbh(k.getJbh());
				p1.setKmlbbm(k.getKmlbbm());
				list.add(p1);
		}
		for(HPzEntity p2:list2){
			String kmdm=p2.getKmdm();
			for(HPzEntity p3:list){
				if(p2.getKmdm().equals(p3.getKmdm())){
					p3.setKmdm(p2.getKmdm());
					p3.setKmmc(p2.getKmmc());
					p3.setKmsx(p2.getKmsx());
					p3.setZjqcye(p2.getZjqcye());
					p3.setZdqcye(p2.getZdqcye());
					p3.setZjfje(p2.getZjfje());
					p3.setZdfje(p2.getZdfje());
					p3.setJqmye(p2.getJqmye());
					p3.setDqmye(p2.getDqmye());
					p3.setJbh(p2.getJbh());
					p3.setKmlbbm(p2.getKmlbbm());
				}
			}
		}
		for(int i=0;i<list.size();i++){//计算2级科目的值
			if(list.get(i).getKmdm().length()==6&&!"201001".equals(list.get(i).getKmdm())&&!"201002".equals(list.get(i).getKmdm())&&!"201003".equals(list.get(i).getKmdm())&&!"201004".equals(list.get(i).getKmdm())&&!"311001".equals(list.get(i).getKmdm())&&!"311002".equals(list.get(i).getKmdm())&&!"401002".equals(list.get(i).getKmdm())&&!"401003".equals(list.get(i).getKmdm())&&!"411001".equals(list.get(i).getKmdm())&&!"411002".equals(list.get(i).getKmdm())){//累计级别号为一的值
				list.get(i).setZjqcye(list.get(i + 1).getZjqcye() + list.get(i + 2).getZjqcye());
				list.get(i).setZdqcye(list.get(i + 1).getZdqcye() + list.get(i + 2).getZdqcye());
				list.get(i).setZjfje(list.get(i + 1).getZjfje() + list.get(i + 2).getZjfje());
				list.get(i).setZdfje(list.get(i + 1).getZdfje() + list.get(i + 2).getZdfje());
				list.get(i).setJqmye(list.get(i + 1).getJqmye() + list.get(i + 2).getJqmye());
				list.get(i).setDqmye(list.get(i + 1).getDqmye() + list.get(i + 2).getDqmye());
			}else if("101".equals(list.get(i).getKmdm().substring(0, 3))&&list.get(i).getKmdm().length()==9){
				sumzjqcye101 = sumzjqcye101 + list.get(i).getZjqcye();
				sumzdqcye101 = sumzdqcye101 + list.get(i).getZdqcye();
				sumzjfje101 = sumzjfje101 + list.get(i).getZjfje();
				sumzdfje101 = sumzdfje101 + list.get(i).getZdfje();
				sumjqmye101 = sumjqmye101 + list.get(i).getJqmye();
				sumdqmye101 = sumdqmye101 + list.get(i).getDqmye();
			}else if("201".equals(list.get(i).getKmdm().substring(0, 3))&&list.get(i).getKmdm().length()==6){
				sumzjqcye201 = sumzjqcye201 + list.get(i).getZjqcye();
				sumzdqcye201 = sumzdqcye201 + list.get(i).getZdqcye();
				sumzjfje201 = sumzjfje201 + list.get(i).getZjfje();
				sumzdfje201 = sumzdfje201 + list.get(i).getZdfje();
				sumjqmye201 = sumjqmye201 + list.get(i).getJqmye();
				sumdqmye201 = sumdqmye201 + list.get(i).getDqmye();
			}else if("311".equals(list.get(i).getKmdm().substring(0, 3))&&list.get(i).getKmdm().length()==6){
				sumzjqcye311 = sumzjqcye311 + list.get(i).getZjqcye();
				sumzdqcye311 = sumzdqcye311 + list.get(i).getZdqcye();
				sumzjfje311 = sumzjfje311 + list.get(i).getZjfje();
				sumzdfje311 = sumzdfje311 + list.get(i).getZdfje();
				sumjqmye311 = sumjqmye311 + list.get(i).getJqmye();
				sumdqmye311 = sumdqmye311 + list.get(i).getDqmye();
			}else if("401".equals(list.get(i).getKmdm().substring(0, 3))&&list.get(i).getKmdm().length()==9){
				sumzjqcye401 = sumzjqcye401 + list.get(i).getZjqcye();
				sumzdqcye401 = sumzdqcye401 + list.get(i).getZdqcye();
				sumzjfje401 = sumzjfje401 + list.get(i).getZjfje();
				sumzdfje401 = sumzdfje401 + list.get(i).getZdfje();
				sumjqmye401 = sumjqmye401 + list.get(i).getJqmye();
				sumdqmye401 = sumdqmye401 + list.get(i).getDqmye();
			}else if("411".equals(list.get(i).getKmdm().substring(0, 3))&&list.get(i).getKmdm().length()==6){
				sumzjqcye411 = sumzjqcye411 + list.get(i).getZjqcye();
				sumzdqcye411 = sumzdqcye411 + list.get(i).getZdqcye();
				sumzjfje411 = sumzjfje411 + list.get(i).getZjfje();
				sumzdfje411 = sumzdfje411 + list.get(i).getZdfje();
				sumjqmye411 = sumjqmye411 + list.get(i).getJqmye();
				sumdqmye411 = sumdqmye411 + list.get(i).getDqmye();
			}
		}
		
		//
		for (int j=0;j<list.size();j++) {
			if ("101".equals(list.get(j).getKmdm())) {//计算102的科目金额和
				list.get(j).setZjqcye(sumzjqcye101);
				list.get(j).setZdqcye(sumzdqcye101);
				list.get(j).setZjfje(sumzjfje101);
				list.get(j).setZdfje(sumzdfje101);
				list.get(j).setJqmye(sumjqmye101);
				list.get(j).setDqmye(sumdqmye101);
			}else if ("201".equals(list.get(j).getKmdm())) {//计算102的科目金额和
				list.get(j).setZjqcye(sumzjqcye201);
				list.get(j).setZdqcye(sumzdqcye201);
				list.get(j).setZjfje(sumzjfje201);
				list.get(j).setZdfje(sumzdfje201);
				list.get(j).setJqmye(sumjqmye201);
				list.get(j).setDqmye(sumdqmye201);
			}else if ("311".equals(list.get(j).getKmdm())) {//计算102的科目金额和
				list.get(j).setZjqcye(sumzjqcye311);
				list.get(j).setZdqcye(sumzdqcye311);
				list.get(j).setZjfje(sumzjfje311);
				list.get(j).setZdfje(sumzdfje311);
				list.get(j).setJqmye(sumjqmye311);
				list.get(j).setDqmye(sumdqmye311);
			}else if ("401".equals(list.get(j).getKmdm())) {//计算102的科目金额和
				list.get(j).setZjqcye(sumzjqcye401);
				list.get(j).setZdqcye(sumzdqcye401);
				list.get(j).setZjfje(sumzjfje401);
				list.get(j).setZdfje(sumzdfje401);
				list.get(j).setJqmye(sumjqmye401);
				list.get(j).setDqmye(sumdqmye401);
			}else if ("411".equals(list.get(j).getKmdm())) {//计算102的科目金额和
				list.get(j).setZjqcye(sumzjqcye411);
				list.get(j).setZdqcye(sumzdqcye411);
				list.get(j).setZjfje(sumzjfje411);
				list.get(j).setZdfje(sumzdfje411);
				list.get(j).setJqmye(sumjqmye411);
				list.get(j).setDqmye(sumdqmye411);
			}
		}	
		}else if("0003".equals(hPzEntity.getZtbm())){
			Double sumzjqcye101 = 0.0;
			Double sumzdqcye101 = 0.0;
			Double sumzjfje101 = 0.0;
			Double sumzdfje101 = 0.0;
			Double sumjqmye101 = 0.0;
			Double sumdqmye101 = 0.0;
			
			Double sumzjqcye201 = 0.0;
			Double sumzdqcye201 = 0.0;
			Double sumzjfje201 = 0.0;
			Double sumzdfje201 = 0.0;
			Double sumjqmye201 = 0.0;
			Double sumdqmye201 = 0.0;
			
			Double sumzjqcye311 = 0.0;
			Double sumzdqcye311 = 0.0;
			Double sumzjfje311 = 0.0;
			Double sumzdfje311 = 0.0;
			Double sumjqmye311 = 0.0;
			Double sumdqmye311 = 0.0;
			
			Double sumzjqcye401 = 0.0;
			Double sumzdqcye401 = 0.0;
			Double sumzjfje401 = 0.0;
			Double sumzdfje401 = 0.0;
			Double sumjqmye401 = 0.0;
			Double sumdqmye401 = 0.0;
			
			Double sumzjqcye411 = 0.0;
			Double sumzdqcye411 = 0.0;
			Double sumzjfje411 = 0.0;
			Double sumzdfje411 = 0.0;
			Double sumjqmye411 = 0.0;
			Double sumdqmye411 = 0.0;
		list2 = baseMapper.yeFseSelect_1(hPzEntity);//查询全部级别号的科目数据
		for(HKmEntity k:listkm){
				HPzEntity p1=new HPzEntity();
				p1.setKmdm(k.getKm());
				p1.setKmmc(k.getKmmc());
				p1.setKmsx(k.getKmsx());
				p1.setZjqcye(0.0);
				p1.setZdqcye(0.0);
				p1.setZjfje(0.0);
				p1.setZdfje(0.0);
				p1.setJqmye(0.0);
				p1.setDqmye(0.0);
				p1.setJbh(k.getJbh());
				p1.setKmlbbm(k.getKmlbbm());
				list.add(p1);
		}
		for(HPzEntity p2:list2){
			String kmdm=p2.getKmdm();
			for(HPzEntity p3:list){
				if(p2.getKmdm().equals(p3.getKmdm())){
					p3.setKmdm(p2.getKmdm());
					p3.setKmmc(p2.getKmmc());
					p3.setKmsx(p2.getKmsx());
					p3.setZjqcye(p2.getZjqcye());
					p3.setZdqcye(p2.getZdqcye());
					p3.setZjfje(p2.getZjfje());
					p3.setZdfje(p2.getZdfje());
					p3.setJqmye(p2.getJqmye());
					p3.setDqmye(p2.getDqmye());
					p3.setJbh(p2.getJbh());
					p3.setKmlbbm(p2.getKmlbbm());
				}
			}
		}
		for(int i=0;i<list.size();i++){//计算2级科目的值
			if(list.get(i).getKmdm().length()==6&&!"300101".equals(list.get(i).getKmdm())&&!"311001".equals(list.get(i).getKmdm())&&!"300102".equals(list.get(i).getKmdm())&&!"400101".equals(list.get(i).getKmdm())&&!"400102".equals(list.get(i).getKmdm())){//累计级别号为一的值
				list.get(i).setZjqcye(list.get(i + 1).getZjqcye() + list.get(i + 2).getZjqcye());
				list.get(i).setZdqcye(list.get(i + 1).getZdqcye() + list.get(i + 2).getZdqcye());
				list.get(i).setZjfje(list.get(i + 1).getZjfje() + list.get(i + 2).getZjfje());
				list.get(i).setZdfje(list.get(i + 1).getZdfje() + list.get(i + 2).getZdfje());
				list.get(i).setJqmye(list.get(i + 1).getJqmye() + list.get(i + 2).getJqmye());
				list.get(i).setDqmye(list.get(i + 1).getDqmye() + list.get(i + 2).getDqmye());
			}else if("1001".equals(list.get(i).getKmdm().substring(0, 4))&&list.get(i).getKmdm().length()==8){
				sumzjqcye101 = sumzjqcye101 + list.get(i).getZjqcye();
				sumzdqcye101 = sumzdqcye101 + list.get(i).getZdqcye();
				sumzjfje101 = sumzjfje101 + list.get(i).getZjfje();
				sumzdfje101 = sumzdfje101 + list.get(i).getZdfje();
				sumjqmye101 = sumjqmye101 + list.get(i).getJqmye();
				sumdqmye101 = sumdqmye101 + list.get(i).getDqmye();
			}else if("3001".equals(list.get(i).getKmdm().substring(0, 4))&&list.get(i).getKmdm().length()==6){
				sumzjqcye201 = sumzjqcye201 + list.get(i).getZjqcye();
				sumzdqcye201 = sumzdqcye201 + list.get(i).getZdqcye();
				sumzjfje201 = sumzjfje201 + list.get(i).getZjfje();
				sumzdfje201 = sumzdfje201 + list.get(i).getZdfje();
				sumjqmye201 = sumjqmye201 + list.get(i).getJqmye();
				sumdqmye201 = sumdqmye201 + list.get(i).getDqmye();
			}else if("4001".equals(list.get(i).getKmdm().substring(0, 4))&&list.get(i).getKmdm().length()==6){
				sumzjqcye311 = sumzjqcye311 + list.get(i).getZjqcye();
				sumzdqcye311 = sumzdqcye311 + list.get(i).getZdqcye();
				sumzjfje311 = sumzjfje311 + list.get(i).getZjfje();
				sumzdfje311 = sumzdfje311 + list.get(i).getZdfje();
				sumjqmye311 = sumjqmye311 + list.get(i).getJqmye();
				sumdqmye311 = sumdqmye311 + list.get(i).getDqmye();
			}else if("5101".equals(list.get(i).getKmdm().substring(0, 4))&&list.get(i).getKmdm().length()==4){
				sumzjqcye401 = sumzjqcye401 + list.get(i).getZjqcye();
				sumzdqcye401 = sumzdqcye401 + list.get(i).getZdqcye();
				sumzjfje401 = sumzjfje401 + list.get(i).getZjfje();
				sumzdfje401 = sumzdfje401 + list.get(i).getZdfje();
				sumjqmye401 = sumjqmye401 + list.get(i).getJqmye();
				sumdqmye401 = sumdqmye401 + list.get(i).getDqmye();
			}else if("5001".equals(list.get(i).getKmdm().substring(0, 4))&&list.get(i).getKmdm().length()==4){
				sumzjqcye411 = sumzjqcye411 + list.get(i).getZjqcye();
				sumzdqcye411 = sumzdqcye411 + list.get(i).getZdqcye();
				sumzjfje411 = sumzjfje411 + list.get(i).getZjfje();
				sumzdfje411 = sumzdfje411 + list.get(i).getZdfje();
				sumjqmye411 = sumjqmye411 + list.get(i).getJqmye();
				sumdqmye411 = sumdqmye411 + list.get(i).getDqmye();
			}
		}
		
		//
		for (int j=0;j<list.size();j++) {
			if ("1001".equals(list.get(j).getKmdm())) {//计算102的科目金额和
				list.get(j).setZjqcye(sumzjqcye101);
				list.get(j).setZdqcye(sumzdqcye101);
				list.get(j).setZjfje(sumzjfje101);
				list.get(j).setZdfje(sumzdfje101);
				list.get(j).setJqmye(sumjqmye101);
				list.get(j).setDqmye(sumdqmye101);
			}else if ("3001".equals(list.get(j).getKmdm())) {//计算102的科目金额和
				list.get(j).setZjqcye(sumzjqcye201);
				list.get(j).setZdqcye(sumzdqcye201);
				list.get(j).setZjfje(sumzjfje201);
				list.get(j).setZdfje(sumzdfje201);
				list.get(j).setJqmye(sumjqmye201);
				list.get(j).setDqmye(sumdqmye201);
			}else if ("4001".equals(list.get(j).getKmdm())) {//计算102的科目金额和
				list.get(j).setZjqcye(sumzjqcye311);
				list.get(j).setZdqcye(sumzdqcye311);
				list.get(j).setZjfje(sumzjfje311);
				list.get(j).setZdfje(sumzdfje311);
				list.get(j).setJqmye(sumjqmye311);
				list.get(j).setDqmye(sumdqmye311);
			}else if ("5101".equals(list.get(j).getKmdm())) {//计算102的科目金额和
				list.get(j).setZjqcye(sumzjqcye401);
				list.get(j).setZdqcye(sumzdqcye401);
				list.get(j).setZjfje(sumzjfje401);
				list.get(j).setZdfje(sumzdfje401);
				list.get(j).setJqmye(sumjqmye401);
				list.get(j).setDqmye(sumdqmye401);
			}else if ("5001".equals(list.get(j).getKmdm())) {//计算102的科目金额和
				list.get(j).setZjqcye(sumzjqcye411);
				list.get(j).setZdqcye(sumzdqcye411);
				list.get(j).setZjfje(sumzjfje411);
				list.get(j).setZdfje(sumzdfje411);
				list.get(j).setJqmye(sumjqmye411);
				list.get(j).setDqmye(sumdqmye411);
			}
		}	
		}
		
		if (hPzEntity.getJbh() == 1) {//查级别号为一级的
			Iterator<HPzEntity> it = list.iterator();
			while (it.hasNext()) {
				HPzEntity x = it.next();
				if (x.getJbh() != 1) {
					it.remove();
				}
			}

		} else if (hPzEntity.getJbh() == 0) {//查全部

		} else if (hPzEntity.getJbh() == 2) {//查级别号为二级的
			Iterator<HPzEntity> it = list.iterator();
			while (it.hasNext()) {
				HPzEntity x = it.next();
				if (x.getJbh() != 2) {
					it.remove();
				}
			}
		} else {//查级别号为三级的
			Iterator<HPzEntity> it = list.iterator();
			while (it.hasNext()) {
				HPzEntity x = it.next();
				if (x.getJbh() != 3) {
					it.remove();
				}
			}
		}

		List<HPzEntity> list1 = new ArrayList<HPzEntity>();
		if (!"all".equals(hPzEntity.getLbbm())){
			String lbbm = hPzEntity.getLbbm();
			for (int i = 0; i < list.size(); i++){
				if(lbbm.equals(list.get(i).getKmlbbm())){
					list1.add(list.get(i));
				}
			}
			return  list1;
		}

		return list;
	}
	
	public String jbh(String ztbm,String jbh){
		String len = "";
		
		List<String> list = new ArrayList<String>();
		list.add("1");
		list.add("2");
		list.add("3");
		
		boolean flag = list.contains(jbh);
		if (flag==false) {
			return("3") ;
		}
		
		if (jbh.equals("1")) {
			len = baseMapper.jbh_1(jbh, ztbm);
		}else {
			if (jbh.equals("2")) {
				len = baseMapper.jbh_2(ztbm);
			}else{
				len = baseMapper.jbh_3(ztbm);
			}
			
		}
			
		if (len.equals("") || len == null) {
			len = "1";
		}
		return len;
	}

	//查询科目类别编码
	@Override
	public List<HKmlbEntity> selectKmlb(Map<String, String> map) {
		List<HKmlbEntity> list = new ArrayList<HKmlbEntity>();
		if (map.get("kmlbbm") != "" &&  map.get("kmlbbm") != null) {
			list = baseMapper.select_kmlbbm1(map.get("kmlbbm"),map.get("ztbm"));
		}else{
			list = baseMapper.select_kmlbbm2(map.get("ztbm"));
		}
		return list;
	}


}
