package nc.impl.sscpfa.pfareport.util;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Map.Entry;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.NCLocator;
import nc.bs.framework.component.RemoteProcessComponent;
import nc.bs.framework.component.RemoteProcessComponetFactory;
import nc.bs.mw.sqltrans.TempTable;
import nc.bs.pf.pub.PfDataCache;
import nc.bs.sscrp.tools.SqlUtils;
import nc.itf.uap.IUAPQueryBS;
import nc.itf.uap.pf.IPFWorkflowQry;
import nc.itf.uap.rbac.IUserManageQuery;
import nc.jdbc.framework.ConnectionFactory;
import nc.jdbc.framework.processor.ArrayListProcessor;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.jdbc.framework.processor.ResultSetProcessor;
import nc.pubitf.bbd.CurrtypeQuery;
import nc.pubitf.bd.accessor.GeneralAccessorFactory;
import nc.pubitf.bd.accessor.IGeneralAccessor;
import nc.vo.bd.accessor.IBDData;
import nc.vo.bd.currtype.CurrtypeVO;
import nc.vo.bd.workcalendar.WorkCalendarDateVO;
import nc.vo.jcom.lang.StringUtil;
import nc.vo.ml.MultiLangUtil;
import nc.vo.pub.BusinessException;
import nc.vo.pub.billtype.BilltypeVO;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pub.workflownote.WorkflownoteVO;
import nc.vo.pub.workflowqry.FlowHistoryUtil;
import nc.vo.sm.UserVO;
import nc.vo.sscpfa.pfareport.report.ReportQueryConditionVO;
import nc.vo.sscpfa.pfareport.report.SSCTaskReportDetailVO;
import nc.vo.uap.historymsg.HistorymsgVO;
import nccloud.commons.lang.StringUtils;
import nccloud.pubitf.sscpub.module.enable.ISCCGroupAndModuleCheck;

public class SSCReportDetailStatisticUtil {
  private static volatile SSCReportDetailStatisticUtil sscReportDetailStatisticUtil;
  
  public static SSCReportDetailStatisticUtil getInstance() {
    if (sscReportDetailStatisticUtil == null)
      synchronized (SSCReportDetailStatisticUtil.class) {
        if (sscReportDetailStatisticUtil == null)
          sscReportDetailStatisticUtil = new SSCReportDetailStatisticUtil(); 
      }  
    return sscReportDetailStatisticUtil;
  }
  
  public String getTempTableName(String table) {
    long currtime = System.currentTimeMillis();
    String tempStr2 = String.valueOf(currtime);
    if (tempStr2.length() > 8)
      tempStr2 = tempStr2.substring(tempStr2.length() - 8); 
    String tableName = table + tempStr2;
    return tableName;
    
  }
  
  public static final int DAYSECONDS= 86400;

  
  
  public String createTempTable(ReportQueryConditionVO reportQueryConditionVO) throws BusinessException {
    
	String tableName = getTempTableName("sscpfa_");
    String vc2 = "VARCHAR2";
    String num = "NUMBER";
    String ch = "CHAR";
    String pretable = "";
    if (GetDatabaseUtil.getDatabaseType() == 2) {
      vc2 = "nvarchar";
      ch = "nchar";
      num = "float";
      pretable = "#";
    } 
    
    StringBuilder sb = new StringBuilder();
    sb.append("billid    " + vc2 + "(20),");
    sb.append("pk_org    " + vc2 + "(20),");
    sb.append("pk_org_name    " + vc2 + "(100),");
    sb.append("pk_group    " + vc2 + "(100),");
    sb.append("billno    " + vc2 + "(200),");
    sb.append("billdate    " + ch + "(19),");
    sb.append("amount    " + num + ",");
    sb.append("pk_currtype    " + vc2 + "(20),");
    sb.append("billmaker    " + vc2 + "(200),");
    sb.append("committime    " + ch + "(19),");
    sb.append("pk_billtypecode    " + vc2 + "(20),");
    sb.append("pk_tradetype    " + vc2 + "(20),");
    sb.append("tradetypecode       " + vc2 + "(20),");
    sb.append("tradetypename       " + vc2 + "(50),");
    sb.append("zgsm_starttime       " + ch + "(19),");
    sb.append("zgsm_endtime       " + ch + "(19),");
    sb.append("zgsm_costtime       " + ch + "(19),");
    sb.append("zgsm_user       " + vc2 + "(200),");
    sb.append("ssc_starttime       " + ch + "(19),");
    sb.append("gxsh_endtime       " + ch + "(19),");
    sb.append("gxsh_costtime       " + ch + "(19),");
    sb.append("gxsh_user       " + vc2 + "(200),");
    sb.append("gxfh_endtime       " + ch + "(19),");
    sb.append("gxfh_costtime       " + ch + "(19),");
    sb.append("gxfh_user       " + vc2 + "(200),");
    sb.append("busi_auditdate       " + ch + "(19),");
    sb.append("qz_endtime       " + ch + "(19),");
    sb.append("qz_costtime       " + ch + "(19),");
    sb.append("qz_user       " + vc2 + "(20),");
    sb.append("js_endtime       " + ch + "(19),");
    sb.append("js_costtime       " + ch + "(19),");
    sb.append("js_user       " + vc2 + "(20),");
    sb.append("gxsp_costtime       " + ch + "(19),");
    sb.append("gxfk_costtime       " + ch + "(19),");
    sb.append("bdlc_costtime       " + num + ",");
    sb.append("gxlc_costtime       " + ch + "(19),");
    sb.append("qlc_costtime       " + ch + "(19),");
    //add by 刘建生、张卓 20220407 新增字段
	sb.append("pay_mny       " + num + ",");//支付金额
	sb.append("paycomfirm_time       " + ch + "(19),");//支付确认单提交时间
	sb.append("getbill_time       " + ch + "(19),");//单据到手时间
	sb.append("recbill_time       " + ch + "(19),");//收单时间
	sb.append("recbill_user       " + vc2 + "(100),");//收单处理人
	
	sb.append("recbill_costtime       " + ch + "(19),");//收单耗时
	sb.append("billstatus        " + vc2 + "(20),");//单据状态
	sb.append("gxsh_starttime       " + ch + "(19),");//审核开始时间
	sb.append("flow_cancelledtime       " + ch + "(19),");//共享审核开始时间
	sb.append("flowpath_sscapprove       " + ch + "(19),");//共享审核开始时间
	
	  
    if (GetDatabaseUtil.getDatabaseType() == 2) {
      sb.append("ts char(19) null default convert(char(19),getdate(),20) ");
    } else {
      sb.append("TS CHAR(19) default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')");
    } 
    try {
      tableName = createTempTable(tableName, sb.toString(), null);
      StringBuilder sb_index = new StringBuilder();
      sb_index.append(" CREATE INDEX i_" + tableName + "_BILLID ON " + tableName + " (billid)  ");
      (new BaseDAO()).executeUpdate(sb_index.toString());
    } catch (SQLException e) {
      throw new BusinessException(e.getMessage());
    } 
    return tableName;
  }
  
  public List<SSCTaskReportDetailVO> reportStatistic(ReportQueryConditionVO reportQueryConditionVO, String tableName) throws BusinessException {
    List<SSCTaskReportDetailVO> taskReportVOs = statistic(reportQueryConditionVO, tableName);
    return taskReportVOs;
  }
  
  public int calcBetweenTheDateRestDayNum( final IUAPQueryBS bs, final Map<String, Integer> map, final UFDate startDate, final UFDate endDate) throws BusinessException {
	  
	  //被减去得时间放在前边
	  String key = startDate.toString() + "_" + endDate.toString();
	  Integer dayNums = map.get(key);
	  if(null == dayNums) {
		  
    	  Collection restDateCol = bs.retrieveByClause(WorkCalendarDateVO.class, " calendardate>='" + startDate.toString() + "'  and calendardate<='" + endDate.toString() +"' and pk_workcalendar = (select pk_workcalendar from bd_workcalendar where code ='Fssc001') and datetype in(1,2) and nvl(dr,0) = 0 ");
    	  dayNums = restDateCol.size();
    	  
    	  map.put(key, dayNums);
	  }
	  
	  return dayNums.intValue();
  }
  
  Map<String, List<WorkCalendarDateVO>> workCalendarDateVOArrMap = new HashMap<>();
  
  public int getSecondsBetween(UFDateTime startDateTime, UFDateTime endDateTime, boolean isGetRidRestDay) throws BusinessException {
	  UFDate startDate = startDateTime.getDate().asBegin();
	  UFDate endDate = endDateTime.getDate().asBegin();
	  
	  boolean isSameDay = startDateTime.isSameDate(endDate); //.sm(startDateTime, endDateTime) == 0;
	  
	  int secondsBetween = UFDateTime.getSecondsBetween(startDateTime, endDateTime);
	 
	  if(secondsBetween == 0) {
		 return secondsBetween;
	  }
	  
	  if(secondsBetween < 0) {
		  throw new BusinessException("请检查传入时间是否正确");
	  }
	  
	 
	  if(!isGetRidRestDay) {
		  return secondsBetween;
	  }
	  
	  String key = startDate.toString() + "_" + endDate.toString();
	  List<WorkCalendarDateVO> list = workCalendarDateVOArrMap.get(key);
	  
	  if( null == list) {
		  IUAPQueryBS bs = NCLocator.getInstance().lookup(IUAPQueryBS.class);
		  Collection restDateCol = bs.retrieveByClause(WorkCalendarDateVO.class, "( calendardate>='" + startDate.toString().substring(0, 10) + "'  and calendardate<='" + endDate.toString().substring(0, 10) +"')  and pk_workcalendar = (select pk_workcalendar from bd_workcalendar where code ='Fssc001') and nvl(dr,0) = 0 ");
		  
		  if(restDateCol.isEmpty() && !isSameDay) {
			  throw new BusinessException("请检查编码为【Fssc001】日历档案是否创建，或档案是否可以正常使用");
		  }
		  
		  
		  final List<WorkCalendarDateVO> tempList = (List<WorkCalendarDateVO>)restDateCol;
		  workCalendarDateVOArrMap.put(key, tempList);
		  list = tempList;
	  }
	 
	 Map<String, Boolean> restDayTageMap = (Map<String, Boolean>)list.stream()
			 .filter(item-> (Objects.nonNull(item.getDatetype()) && Objects.nonNull(item.getCalendardate())))
			 .collect(Collectors.toMap(item-> item.getCalendardate().toString() , item-> (item.getDatetype() == 1 || item.getDatetype() == 2) ));

	 int restDayNum = 0; 
	 for(Entry entry : restDayTageMap.entrySet()) {
		 if((boolean)entry.getValue()) {
			 restDayNum++;
		 }
	 }
			
	 //没有休息日
	 if(restDayNum == 0) {
		 return secondsBetween;
	 }
	 
	//开始时间，结束时间没有工作日
	 if(!restDayTageMap.containsValue(false)) {
		return 0;
	 }

	 //减去休息日时间
	 Boolean stateDateIsRestDay = restDayTageMap.get(startDate.toString().substring(0, 10));
	 Boolean endDateIsRestDay = restDayTageMap.get(endDate.toString().substring(0, 10));
	 
	 if(!stateDateIsRestDay && !endDateIsRestDay) {
		 
		 return secondsBetween - restDayNum * DAYSECONDS;
	 }
	 
	 
	 if(!stateDateIsRestDay && endDateIsRestDay) {
		 WorkCalendarDateVO lastWork = null;
		 for(WorkCalendarDateVO item : list) {
			if(restDayTageMap.get(item.getCalendardate().toString())) {
				lastWork = item;
				break;
			}
		 }
		 
		 secondsBetween = UFDateTime.getSecondsBetween(startDateTime, new UFDateTime(lastWork.getCalendardate()+" 00:00:00"));
	 }
	 
	 if(stateDateIsRestDay && !endDateIsRestDay) {
		 WorkCalendarDateVO firstWork = null;
		 for(WorkCalendarDateVO item : list) {
			if(!restDayTageMap.get(item.getCalendardate().toString())) {
				firstWork = item;
				break;
			}
		 }
		 
		 secondsBetween = UFDateTime.getSecondsBetween(new UFDateTime(firstWork.getCalendardate()+" 00:00:00"), endDateTime);
	 }
	 
	 return secondsBetween;
  }
  
  
  
  
  private List<SSCTaskReportDetailVO> statistic(ReportQueryConditionVO reportQueryConditionVO, String tableName) throws BusinessException {
    String suffix = MultiLangUtil.getCurrentLangSeqSuffix();
    String timeUnit = reportQueryConditionVO.getTimeUnit();
    StringBuilder sbd = new StringBuilder();
    ISCCGroupAndModuleCheck groupAndModuleCheck = (ISCCGroupAndModuleCheck)NCLocator.getInstance().lookup(ISCCGroupAndModuleCheck.class);
    if (groupAndModuleCheck.isProductModuleInstalled("3607")) {
      sbd.append(" update " + tableName + "  set " + tableName + ".gxlc_costtime = 'N' ");
      sbd.append(" where not exists (select 1 from cmp_settlement C where " + tableName + ".billid = C.pk_busibill ) ");
    } else {
      sbd.append(" update " + tableName + "  set " + tableName + ".gxlc_costtime = 'N' ");
    } 
    (new BaseDAO()).executeUpdate(sbd.toString());
    StringBuilder sb = new StringBuilder("select pfa.*,isnull(u1.user_name" + suffix + ",u1.user_name) qz_user_name,isnull(u2.user_name" + suffix + ",u2.user_name) js_user_name from " + tableName + " pfa ");
    sb.append(" left join sm_user u1 on u1.cuserid = pfa.qz_user ");
    sb.append(" left join sm_user u2 on u2.cuserid = pfa.js_user ");
    sb.append(" order by pfa.billdate ");
    int digit = 2;
    List<HashMap<String, Object>> ls = (List<HashMap<String, Object>>)(new BaseDAO()).executeQuery(sb.toString().toString(), (ResultSetProcessor)new MapListProcessor());
    List<SSCTaskReportDetailVO> taskDetailReportVOs = new ArrayList<>();
    Map<String, BilltypeVO> pk2billtypevo = new HashMap<>();
    HashMap<String, BilltypeVO> billtypes = PfDataCache.getBilltypes();
    for (BilltypeVO billtypevo : billtypes.values())
      pk2billtypevo.put(billtypevo.getPk_billtypeid(), billtypevo); 
    IGeneralAccessor orgAccessor = GeneralAccessorFactory.getAccessor("985be8a4-3a36-4778-8afe-2d8ed3902659");
    
    IPFWorkflowQry pfWorkflowQry = NCLocator.getInstance().lookup(IPFWorkflowQry.class);
	
	//String[] billIds, String[] billOrTranstypes, int iWorkflowOrApproveflow, int allOrFinished
	
    List<String> pk_bxjkList = new ArrayList<String>( ls.size() );
    List<String> Pk_billtypecodeList = new ArrayList<String>( ls.size() );
    //mrcopy 2022/04/12 add
    for (Map<String, Object> v : ls) {
    	
    	pk_bxjkList.add(v.get( "billid" ).toString());
    	BilltypeVO billtypevo = pk2billtypevo.get(v.get("pk_tradetype"));
    	if(null != billtypevo ) {
    		Pk_billtypecodeList.add( billtypevo.getPk_billtypecode() );
    	}
    }
    Pk_billtypecodeList = Pk_billtypecodeList.stream().distinct().collect( Collectors.toList());
    
    //TODO 2022/04/22 标准产品 iWorkflowOrApproveflow  =4 有可能存在问题  allOrFinished = 0
    String[] tempStrArr = new String[0];
    WorkflownoteVO[] workflownoteVOArr = new WorkflownoteVO[0]; //pfWorkflowQry.queryWorkitemsBatch(pk_bxjkList.toArray( tempStrArr ), Pk_billtypecodeList.toArray( tempStrArr ), 4, 0); //queryWorkitems
    List<WorkflownoteVO> workflownoteVOList = Arrays.asList(workflownoteVOArr);
   
    Map<String, List<WorkflownoteVO>> workflownoteVOListMap = workflownoteVOList.stream().collect( Collectors.groupingBy( WorkflownoteVO::getBillid ) );
    
    Map<String, Integer> BetweenTheDateRestDayNumMap = new HashMap<>();

	IUAPQueryBS bs = NCLocator.getInstance().lookup(IUAPQueryBS.class);
	
	ArrayList al = (ArrayList) bs.executeQuery("select billid,min(senddate) from  pub_workflownote  where billid in('" + StringUtil.toString(pk_bxjkList, "','") + "') group by billid ", new ArrayListProcessor());
	
	Map<String, String> billCommintDateMap = new HashMap<>();
	for(Object item : al) {
		Object[] v = (Object[])item ;
		billCommintDateMap.put((String)v[0], (String)v[1] );
	}
	Map<String, SSCTaskReportDetailVO>  busiid_rel= new HashMap<>();
    
	final WorkflownoteVO[] tempWorkflownoteVO = new WorkflownoteVO[0];
    for (Map<String, Object> v : ls) {
    	
      SSCTaskReportDetailVO taskDetailReportVO = new SSCTaskReportDetailVO();
      BilltypeVO billtypevo = pk2billtypevo.get(v.get("pk_tradetype"));
      
      String billid = v.get("billid").toString();
      List<WorkflownoteVO> tempBillWorkFlownoteVOList = workflownoteVOListMap.get(billid);
      
      HistorymsgVO[] historynsfVOs = null;
      if(null != tempBillWorkFlownoteVOList && !tempBillWorkFlownoteVOList.isEmpty()) {
    	  historynsfVOs = FlowHistoryUtil.convertHistorymsgVOs(billtypevo.getPk_billtypecode(), tempBillWorkFlownoteVOList.toArray( tempWorkflownoteVO ) );
      }else {
    	  historynsfVOs = new HistorymsgVO[0];
      }
      
      List<HistorymsgVO> historynsfVOList = Arrays.asList( historynsfVOs );
      
      
      List<HistorymsgVO> finalHistorymsgVOList = historynsfVOList.stream().filter(item -> "收单岗".equals(item.getApprovelink()) && "已完成".equals(item.getApprovestatus())).collect(Collectors.toList());
      
      
      IBDData orgdoc = orgAccessor.getDocByPk(v.get("pk_org").toString());
      taskDetailReportVO.setBusiid(v.get("billid").toString());
      taskDetailReportVO.setPk_tradetype(v.get("pk_tradetype").toString());
      if (billtypevo != null) {
        taskDetailReportVO.setPk_billtypecode((billtypevo.getParentbilltype() == null) ? billtypevo.getPk_billtypecode() : billtypevo.getParentbilltype());
        taskDetailReportVO.setTradetype_code((billtypevo.getPk_billtypecode() != null) ? billtypevo.getPk_billtypecode().toString().trim() : "");
        taskDetailReportVO.setTradetype_name(billtypevo.getBilltypenameOfCurrLang());
      } 
      taskDetailReportVO.setBilldate((v.get("billdate") != null) ? v.get("billdate").toString().trim() : "");
      taskDetailReportVO.setBillno((v.get("billno") != null) ? v.get("billno").toString().trim() : "");
      if (v.get("pk_currtype") != null && StringUtils.isNotBlank(v.get("pk_currtype").toString())) {
        CurrtypeVO currtypeVO = CurrtypeQuery.getInstance().getCurrtypeVO(v.get("pk_currtype").toString());

        if (currtypeVO == null) {
          digit = 2;
        } else {
          digit = currtypeVO.getCurrdigit().intValue();
        } 
      } 
      taskDetailReportVO.setAmount((v.get("amount") != null) ? caculateMoney(v.get("amount").toString(), digit) : "");
      taskDetailReportVO.setCommittime((v.get("committime") != null) ? v.get("committime").toString() : "");
      taskDetailReportVO.setPk_org(v.get("pk_org").toString());
      taskDetailReportVO.setPk_group(v.get("pk_group").toString());
      taskDetailReportVO.setBillmaker((v.get("billmaker") != null) ? v.get("billmaker").toString().trim() : "");
      taskDetailReportVO.setPk_org_name(orgdoc.getName().toString());
      taskDetailReportVO.setZgsm_user((v.get("zgsm_user") != null) ? v.get("zgsm_user").toString().trim() : "");
      taskDetailReportVO.setGxsh_user((v.get("gxsh_user") != null) ? v.get("gxsh_user").toString().trim() : "");
      taskDetailReportVO.setGxfh_user((v.get("gxfh_user") != null) ? v.get("gxfh_user").toString().trim() : "");
      taskDetailReportVO.setQz_user((v.get("qz_user") != null) ? v.get("qz_user_name").toString().trim() : "");
      taskDetailReportVO.setJs_user((v.get("js_user") != null) ? v.get("js_user_name").toString().trim() : "");
     
      double gxsp_costtime = 0.0D;
      double gxfk_costtime = 0.0D;
      String bdlc_costtime = "";
      double gxlc_costtime = 0.0D;//gxsp_costtime + gxfk_costtime
      double qlc_costtime = 0.0D;//gxlc_costtime + bdlc_costtime
      Boolean hasSignAndSettle = Boolean.valueOf(false);
      Boolean hasGXApprove = Boolean.valueOf(false);
      
      
      //处理审核耗时 mrcopy 2022/04/25 update start
      double gxsh_costtime = (v.get("gxsh_costtime") != null) ? Double.valueOf(v.get("gxsh_costtime").toString().trim()) : 0.0d;
      
      String gxsh_starttimeStr = (v.get("gxsh_starttime") != null) ? v.get("gxsh_starttime").toString() : "";
      String gxsh_endtimeStr = (v.get("gxsh_endtime") != null) ? v.get("gxsh_endtime").toString() : "";
      
      if( !StringUtil.isEmptyWithTrim( gxsh_endtimeStr ) ) {
    	  if( !StringUtil.isEmptyWithTrim( gxsh_starttimeStr ) ) {
    		  UFDateTime gxsh_starttime = new UFDateTime(gxsh_starttimeStr);
    		  UFDateTime gxsh_endtime = new UFDateTime(gxsh_endtimeStr);
    		  
    		  UFDateTime ssc_starttime = new UFDateTime( (v.get("ssc_starttime") != null) ? v.get("ssc_starttime").toString().trim() : "");
    		  
//    		  gxsh_costtime = UFDateTime.getSecondsBetween(ssc_starttime, gxsh_endtime);
//    		  
//    		  int restDayNums = calcBetweenTheDateRestDayNum(bs, BetweenTheDateRestDayNumMap, gxsh_starttime.getDate(), gxsh_endtime.getDate());
//    		  gxsh_costtime +=  - restDayNums * DAYSECONDS;
//    		  
//    		  //处理节假日做单情况
//    		  gxsh_costtime = UFDouble.ZERO_DBL.compareTo( new UFDouble(gxsh_costtime)) == -1 ? gxsh_costtime : UFDouble.ZERO_DBL.doubleValue();
    		  
    		  gxsh_costtime = getSecondsBetween(ssc_starttime, gxsh_endtime, true);
          
    	  }  
      }
      //处理审核耗时 mrcopy 2022/04/25 update end
      
      if (v.get("gxsp_costtime") != null && v.get("gxsp_costtime").toString().trim().equals("Y")) {
        if (v.get("gxsh_costtime") != null && Integer.parseInt(v.get("gxsh_costtime").toString().trim()) > 0)
        	//mrocpy 2022/04/24 update
        	//gxsp_costtime = add(String.valueOf(gxsp_costtime), v.get("gxsh_costtime").toString().trim());
        	gxsp_costtime = add(String.valueOf(gxsp_costtime), gxsh_costtime + "");
        	//mrocpy 2022/04/24 update
        	
        if (v.get("gxfh_costtime") != null && Integer.parseInt(v.get("gxfh_costtime").toString().trim()) > 0)
          gxsp_costtime = add(String.valueOf(gxsp_costtime), v.get("gxfh_costtime").toString().trim()); 
        hasGXApprove = Boolean.valueOf(true);
      } else {
        gxsp_costtime = 0.0D;
      } 
      if (v.get("qz_costtime") != null && Integer.parseInt(v.get("qz_costtime").toString().trim()) >= 0 && v.get("js_costtime") != null && Integer.parseInt(v.get("js_costtime").toString().trim()) >= 0) {
//        gxfk_costtime = add(v.get("qz_costtime").toString().trim(), v.get("js_costtime").toString().trim());
        hasSignAndSettle = Boolean.valueOf(true);
      } else {
//        gxfk_costtime = 0.0D;
      } 
      
      
      //处理付款耗时 start
      /**
       *	签字耗时： 	qz_endtime 签字时间 - busi_auditdate 业务单据审核日期  （标准产品） 
       *	计算耗时：  settledate 结算时间 - qz_endtime 签字时间
       *	js_endtime =  settledate（标准产品）
       *	qz_endtime = B.signdate
       *	
       *	
       */
      String busi_auditdateStr = (v.get("busi_auditdate") != null) ? v.get("busi_auditdate").toString() : "";
      String js_endtimeStr = (v.get("js_endtime") != null) ? v.get("js_endtime").toString() : "";
      String qz_endtimeStr = (v.get("qz_endtime") != null) ? v.get("qz_endtime").toString().trim() : ""; 
      //流程用时可能存在问题
      //签字耗时
      double qz_costtime = 0.00D;
      if( !StringUtil.isEmptyWithTrim(busi_auditdateStr) && !StringUtil.isEmptyWithTrim(qz_endtimeStr)) {
    	  
//    	  qz_costtime = UFDateTime.getSecondsBetween( new UFDateTime(busi_auditdateStr), new UFDateTime(qz_endtimeStr));
    	  qz_costtime = getSecondsBetween(new UFDateTime(busi_auditdateStr), new UFDateTime(qz_endtimeStr), true);
    	  
    	  if(UFBoolean.FALSE.toString().equals( (v.get("isautosign") != null) ? v.get("isautosign").toString() : "" )) {
    		  qz_costtime += new Double((null != v.get("flow_cancelledtime")) ? v.get("flow_cancelledtime").toString().trim(): "0.0");  
    	  }
    	  
    	  
//    	  int restDayNums = calcBetweenTheDateRestDayNum(bs, BetweenTheDateRestDayNumMap, new UFDate(busi_auditdateStr), new UFDate(js_endtimeStr));
//    	  qz_costtime = qz_costtime - restDayNums * DAYSECONDS;
    	  
      }
      //结算耗时
      if( !StringUtil.isEmptyWithTrim(js_endtimeStr) &&  !StringUtil.isEmptyWithTrim(qz_endtimeStr)) {
    	  gxfk_costtime = qz_costtime;
    	  
    	  UFDateTime qz_endTime = new UFDateTime(qz_endtimeStr);
    	  UFDateTime js_endTime = new UFDateTime(js_endtimeStr);
    	  
//    	  gxfk_costtime +=  UFDateTime.getSecondsBetween( qz_endTime, js_endTime);
    	  gxfk_costtime +=  getSecondsBetween(qz_endTime, js_endTime, true);
    	  
    	  if(UFBoolean.TRUE.toString().equals( (v.get("isautosign") != null) ? v.get("isautosign").toString() : "" )) {
    		  gxfk_costtime += new Double((null != v.get("flow_cancelledtime")) ? v.get("flow_cancelledtime").toString().trim(): "0.0");
    	  }
//    	  int restDayNums = calcBetweenTheDateRestDayNum(bs, BetweenTheDateRestDayNumMap, qz_endTime.getDate(), js_endTime.getDate());
//    	  gxfk_costtime = gxfk_costtime - restDayNums * DAYSECONDS;
      }
      
     //处理付款耗时 end
      
      
      if (v.get("bdlc_costtime") != null)
        bdlc_costtime = String.valueOf(v.get("bdlc_costtime")); 
      if (gxsp_costtime != 0.0D || hasGXApprove.booleanValue())
        if (v.get("gxlc_costtime") != null && v.get("gxlc_costtime").toString().trim().equals("N")) {
          gxlc_costtime = gxsp_costtime;
          
          //mrocpy 2022/04/12 update
          //qlc_costtime = (new UFDouble(bdlc_costtime)).doubleValue() + gxlc_costtime;
        } else if (gxfk_costtime != 0.0D || hasSignAndSettle.booleanValue()) {
          gxlc_costtime = gxsp_costtime + gxfk_costtime;
          //mrocpy 2022/04/12 update
          //qlc_costtime = (new UFDouble(bdlc_costtime)).doubleValue() + gxlc_costtime;
        } else {
          gxlc_costtime = 0.0D;
          
          //mrocpy 2022/04/12 update
          //qlc_costtime = 0.0D;
        }
      
      //mrocpy 2022/04/12 addd start
      
      
      String js_endtime = (v.get("js_endtime") != null) ? v.get("js_endtime").toString().trim() : "";
//      String billid = v.get("billid").toString();
      String billCommintDate = billCommintDateMap.get(billid);
      if(!StringUtil.isEmptyWithTrim(js_endtime) && !StringUtil.isEmptyWithTrim(billCommintDate)) {
    	  UFDateTime jsEndtime = new UFDateTime(js_endtime);
    	  UFDateTime billCommintDateTime = new UFDateTime(billCommintDate);
//    	  qlc_costtime = UFDateTime.getSecondsBetween(billCommintDateTime, jsEndtime);
    	  
//    	  Collection restDateCol = bs.retrieveByClause(WorkCalendarDateVO.class, " calendardate>='" + jsEndtime.getDate().toStdString() + "'  and calendardate<='"+billCommintDateTime.getDate().toStdString()+"' and pk_workcalendar = (select pk_workcalendar from bd_workcalendar where code ='Fssc001') and datetype in(1,2) and nvl(dr,0) = 0 ");
    	  
//    	  qlc_costtime = qlc_costtime - restDateCol.size() * DAYSECONDS;
//    	  qlc_costtime = UFDouble.ZERO_DBL.compareTo( new UFDouble(qlc_costtime)) == -1 ? qlc_costtime : UFDouble.ZERO_DBL.doubleValue();
    	  qlc_costtime = getSecondsBetween(billCommintDateTime, jsEndtime, true);
      }
      
      
      
      //mrocpy 2022/04/12 end
      
      taskDetailReportVO.setZgsm_starttime((v.get("zgsm_starttime") != null) ? v.get("zgsm_starttime").toString().trim() : "");
      taskDetailReportVO.setZgsm_endtime((v.get("zgsm_endtime") != null) ? v.get("zgsm_endtime").toString().trim() : "");
      taskDetailReportVO.setZgsm_costtime(caculateTime((v.get("zgsm_costtime") != null) ? v.get("zgsm_costtime").toString().trim() : "", timeUnit));
      taskDetailReportVO.setSsc_starttime((v.get("ssc_starttime") != null) ? v.get("ssc_starttime").toString().trim() : "");
      taskDetailReportVO.setGxsh_endtime((v.get("gxsh_endtime") != null) ? v.get("gxsh_endtime").toString().trim() : "");
      
      //mrocpy 2022/04/12 update
//      taskDetailReportVO.setGxsh_costtime(caculateTime((v.get("gxsh_costtime") != null) ? v.get("gxsh_costtime").toString().trim() : "", timeUnit));
      taskDetailReportVO.setGxsh_costtime(caculateTime(gxsh_costtime+"", timeUnit));
     //单据到手时间
      taskDetailReportVO.setGetbill_time( (v.get("getbill_time") != null) ? v.get("getbill_time").toString().trim() : "");
      //mrocpy 2022/04/12 update
      
      taskDetailReportVO.setGxfh_endtime((v.get("gxfh_endtime") != null) ? v.get("gxfh_endtime").toString().trim() : "");
      taskDetailReportVO.setGxfh_costtime(caculateTime((v.get("gxfh_costtime") != null) ? v.get("gxfh_costtime").toString().trim() : "", timeUnit));
      taskDetailReportVO.setBusi_auditdate((v.get("busi_auditdate") != null) ? v.get("busi_auditdate").toString().trim() : "");
      taskDetailReportVO.setQz_endtime((v.get("qz_endtime") != null) ? v.get("qz_endtime").toString().trim() : "");
      //mrocpy 2022/04/12 update
//      taskDetailReportVO.setQz_costtime(caculateTime((v.get("qz_costtime") != null) ? v.get("qz_costtime").toString().trim() : "", timeUnit));
      taskDetailReportVO.setQz_costtime( caculateTime( qz_costtime+"", timeUnit));
      //mrocpy 2022/04/12 update
      taskDetailReportVO.setJs_endtime((v.get("js_endtime") != null) ? v.get("js_endtime").toString().trim() : "");
      taskDetailReportVO.setJs_costtime(caculateTime((v.get("js_costtime") != null) ? v.get("js_costtime").toString().trim() : "", timeUnit));
      taskDetailReportVO.setGxsp_costtime(caculateTime(String.valueOf(gxsp_costtime), timeUnit));
      taskDetailReportVO.setGxfk_costtime(caculateTime(String.valueOf(gxfk_costtime), timeUnit));
      taskDetailReportVO.setBdlc_costtime(caculateTime(String.valueOf(bdlc_costtime), timeUnit));
      taskDetailReportVO.setGxlc_costtime(caculateTime(String.valueOf(gxlc_costtime), timeUnit));
      taskDetailReportVO.setQlc_costtime(caculateTime(String.valueOf(qlc_costtime), timeUnit));
      
      //20222/04/08 mrcopy add 
      taskDetailReportVO.setPay_mny((v.get("pay_mny") != null) ? new UFDouble(v.get("pay_mny").toString().trim(), 2).toString() : "");
      
      taskDetailReportVO.setPaycomfirm_time(  (v.get("paycomfirm_time") != null) ? new UFDateTime(v.get("paycomfirm_time").toString()) .toString() : "");
      
      
      String flowpath_sscapprove = (v.get("flowpath_sscapprove") != null) ? new UFDateTime(v.get("flowpath_sscapprove").toString()) .toString() : "";
      String recbill_time = (v.get("recbill_time") != null) ? new UFDateTime(v.get("recbill_time").toString()) .toString() : "" ;
      
      if( !StringUtil.isEmptyWithTrim(flowpath_sscapprove) && !StringUtil.isEmptyWithTrim(recbill_time) ) {
    	  UFDateTime sscapprove = new UFDateTime(flowpath_sscapprove);
    	  UFDateTime recbillTime = new UFDateTime(recbill_time);
//    	  int seconds = UFDateTime.getSecondsBetween(sscapprove, recbillTime);
//    	  
//    	  int restDayNums = calcBetweenTheDateRestDayNum(bs, BetweenTheDateRestDayNumMap, sscapprove.getDate(), recbillTime.getDate());
//    	  seconds = seconds - restDayNums * DAYSECONDS;
    	  int seconds =  getSecondsBetween( sscapprove, recbillTime, true);
    	  
    	  taskDetailReportVO.setRecbill_costtime(caculateTime(seconds+"", timeUnit));  
      }
      
      taskDetailReportVO.setRecbill_time(recbill_time );
      taskDetailReportVO.setRecbill_user( (v.get("recbill_user") != null) ? v.get("recbill_user").toString() : "" );
      //20222/04/08 mrcopy add
      
      
    //add by  sdan 添加单据状态20220415   js_endtime 结算日期 paycomfirm_time 支付确认单提交时间 busi_auditdate  签字时间 recbill_time 收单时间 gxsh_endtime 共享审核时间 getbill_time 单据到手时间均为空
//    已结算：结算日期不为空
//    支付失败：结算日期为空，支付确认单提交时间不为空
//    已签字：结算日期、支付确认单提交时间为空，签字时间不为空
//    已收单：结算日期、支付确认单提交时间、签字时间为空，收单时间不为空
//    共享已审核：结算日期、支付确认单提交时间、签字时间、收单时间为空，共享审核时间不为空
//    共享已提取：结算日期、支付确认单提交时间、签字时间、收单时间、共享审核时间为空，单据到手时间不为空
//    待提取：结算日期、支付确认单提交时间、签字时间、收单时间、共享审核时间、单据到手时间均为空
	    if(v.get("js_endtime") !=null ) {   
	  	  taskDetailReportVO.setBillstatus("已结算");  
	    }else if(v.get("js_endtime")  == null && v.get("paycomfirm_time") != null) {
	  	  taskDetailReportVO.setBillstatus("支付失败");  
	    }else if(v.get("js_endtime")  == null && v.get("paycomfirm_time") == null &&  v.get("busi_auditdate") !=null) {
	  	  taskDetailReportVO.setBillstatus("已签字");  
	    }else if(v.get("js_endtime")  == null && v.get("paycomfirm_time") == null &&  v.get("busi_auditdate") ==null &&  v.get("recbill_time") !=null) {
	  	  taskDetailReportVO.setBillstatus("已收单");  
	    }else if(v.get("js_endtime")  == null && v.get("paycomfirm_time") == null &&  v.get("busi_auditdate") ==null &&  v.get("recbill_time") ==null &&  v.get("gxsh_endtime") !=null) {
	  	  taskDetailReportVO.setBillstatus("共享已审核");  
	    }else if(v.get("js_endtime")  == null && v.get("paycomfirm_time") == null &&  v.get("busi_auditdate") ==null &&  v.get("recbill_time") ==null &&  v.get("gxsh_endtime") ==null && v.get("getbill_time") !=null) {
	  	  taskDetailReportVO.setBillstatus("共享已提取");  
	    }else if(v.get("js_endtime")  == null && v.get("paycomfirm_time") == null &&  v.get("busi_auditdate") ==null &&  v.get("recbill_time") ==null &&  v.get("gxsh_endtime") ==null && v.get("getbill_time") ==null) {
	  	  taskDetailReportVO.setBillstatus("待提取");  
	    }
	    taskDetailReportVOs.add(taskDetailReportVO);
	    
	    busiid_rel.put(taskDetailReportVO.getBillno(), taskDetailReportVO);
    } 
    //add by sdan 添加共享单据绩效明细表查询条件
    for (int i = 0; i < taskDetailReportVOs.size(); i++) {
    	  String up_sql="update "+tableName+" set ssc_starttime = '"+removeNull(taskDetailReportVOs.get(i).getSsc_starttime())+"', gxsh_endtime = '"+removeNull(taskDetailReportVOs.get(i).getGxsh_endtime())+"' ,gxsh_costtime = '"+removeNull(taskDetailReportVOs.get(i).getGxsh_costtime())+"' ,gxsh_user='"+taskDetailReportVOs.get(i).getGxsh_user()+"',gxfh_endtime= '"+removeNull(taskDetailReportVOs.get(i).getGxfh_endtime())+"' ,gxfh_costtime= '"+removeNull(taskDetailReportVOs.get(i).getGxfh_costtime())+"' "
   	  		+ ",gxfh_user='"+taskDetailReportVOs.get(i).getGxfh_user()+"',busi_auditdate='"+removeNull(taskDetailReportVOs.get(i).getBusi_auditdate())+"' ,qz_endtime='"+removeNull(taskDetailReportVOs.get(i).getQz_endtime())+"',qz_costtime='"+removeNull(taskDetailReportVOs.get(i).getQz_costtime())+"',qz_user='"+taskDetailReportVOs.get(i).getQz_user()+"',js_endtime='"+removeNull(taskDetailReportVOs.get(i).getJs_endtime())+"',js_costtime='"+removeNull(taskDetailReportVOs.get(i).getJs_costtime())+"' "
    	  		+ ",js_user='"+taskDetailReportVOs.get(i).getJs_user()+"',gxsp_costtime='"+removeNull(taskDetailReportVOs.get(i).getGxsp_costtime())+"',gxfk_costtime='"+removeNull(taskDetailReportVOs.get(i).getGxfk_costtime())+"',bdlc_costtime='"+removeNull(taskDetailReportVOs.get(i).getBdlc_costtime())+"',gxlc_costtime='"+removeNull(taskDetailReportVOs.get(i).getGxlc_costtime())+"',qlc_costtime='"+removeNull(taskDetailReportVOs.get(i).getQlc_costtime())+"',zgsm_starttime='"+removeNull(taskDetailReportVOs.get(i).getZgsm_starttime())+"' " 
    	  		+ ",zgsm_endtime='"+removeNull(taskDetailReportVOs.get(i).getZgsm_endtime())+"',zgsm_costtime='"+removeNull(taskDetailReportVOs.get(i).getZgsm_costtime())+"',zgsm_user= '"+taskDetailReportVOs.get(i).getZgsm_user()+"',pay_mny='"+taskDetailReportVOs.get(i).getPay_mny()+"',paycomfirm_time='"+removeNull(taskDetailReportVOs.get(i).getPaycomfirm_time())+"',getbill_time='"+removeNull(taskDetailReportVOs.get(i).getGetbill_time())+"',recbill_time='"+removeNull(taskDetailReportVOs.get(i).getRecbill_time())+"' " 
    	  		+ ",recbill_user='"+taskDetailReportVOs.get(i).getRecbill_user()+"',recbill_costtime='"+removeNull(taskDetailReportVOs.get(i).getRecbill_costtime())+"',billstatus='"+taskDetailReportVOs.get(i).getBillstatus()+"',pk_org='"+taskDetailReportVOs.get(i).getPk_org()+"' ,pk_org_name='"+taskDetailReportVOs.get(i).getPk_org_name()+"',pk_group='"+taskDetailReportVOs.get(i).getPk_group()+"' ,pk_billtypecode='"+taskDetailReportVOs.get(i).getPk_billtypecode()+"' ,pk_tradetype='"+taskDetailReportVOs.get(i).getPk_tradetype()+"'  ,amount='"+taskDetailReportVOs.get(i).getAmount()+"' where billno = '"+taskDetailReportVOs.get(i).getBillno()+"' ";
    
     	(new BaseDAO()).executeUpdate(up_sql);
	}
    String billstatus = reportQueryConditionVO.getBillstatus();
    String pressc_starttime = reportQueryConditionVO.getPressc_starttime();//入池时间区间
    String endssc_starttime = reportQueryConditionVO.getEndssc_starttime();
    String pregetbill_time = reportQueryConditionVO.getPregetbill_time();//单据到手区间
    String endgetbill_time = reportQueryConditionVO.getEndgetbill_time();
    String pregxsh_endtime = reportQueryConditionVO.getPregxsh_endtime();//共享审核时间
    String endgxsh_endtime = reportQueryConditionVO.getEndgxsh_endtime();
    String gxsh_user = reportQueryConditionVO.getGxsh_user();//共享审核人
    String pregxfh_endtime = reportQueryConditionVO.getPregxfh_endtime();//共享复核时间
    String endgxfh_endtime = reportQueryConditionVO.getEndgxfh_endtime();
    String gxfh_user = reportQueryConditionVO.getGxfh_user();//共享复核人
    String recbill_user = reportQueryConditionVO.getRecbill_user();//收单处理人
    String prerecbill_time = reportQueryConditionVO.getPrerecbill_time();//收单时间
    String endrecbill_time = reportQueryConditionVO.getEndrecbill_time();
    String prebusi_auditdate = reportQueryConditionVO.getPrebusi_auditdate();//签字开始时间
    String endbusi_auditdate = reportQueryConditionVO.getEndbusi_auditdate();
    String preqz_endtime = reportQueryConditionVO.getPreqz_endtime();//签字时间
    String endqz_endtime = reportQueryConditionVO.getEndqz_endtime();
    String qz_user = reportQueryConditionVO.getQz_user();//签字人
    String prepaycomfirm_time = reportQueryConditionVO.getPrepaycomfirm_time();//支付确认单提交时间
    String endpaycomfirm_time = reportQueryConditionVO.getEndpaycomfirm_time();
    String prejs_endtime = reportQueryConditionVO.getPrejs_endtime();//结算时间
    String endjs_endtime = reportQueryConditionVO.getEndjs_endtime();
    String js_user = reportQueryConditionVO.getJs_user();//结算人
    
    StringBuilder sb_sql = new StringBuilder();
    sb_sql.append("select * from "+tableName+" ");
    sb_sql.append("   WHERE 1=1 ");
    if (StringUtils.isNotEmpty(billstatus)) {
    	sb_sql.append(" AND billstatus = '"  +billstatus+"' ");
     }
    
    if(StringUtils.isNotEmpty(pressc_starttime) && StringUtils.isNotEmpty(endssc_starttime)) {
    	sb_sql.append(" AND ssc_starttime BETWEEN '" + TimestampUtils.getFormatDate(pressc_starttime) + "' AND  ");
    	sb_sql.append(" '" + TimestampUtils.getFormatDate(endssc_starttime) + "'                              "); 
    }
    if(StringUtils.isNotEmpty(pregetbill_time) && StringUtils.isNotEmpty(endgetbill_time)) {
    	sb_sql.append(" AND getbill_time BETWEEN '" + TimestampUtils.getFormatDate(pregetbill_time) + "' AND  ");
    	sb_sql.append(" '" + TimestampUtils.getFormatDate(endgetbill_time) + "'                              "); 
    }
    
    if(StringUtils.isNotEmpty(pregxsh_endtime) && StringUtils.isNotEmpty(endgxsh_endtime)) {
    	sb_sql.append(" AND gxsh_endtime BETWEEN '" + TimestampUtils.getFormatDate(pregxsh_endtime) + "' AND  ");
    	sb_sql.append(" '" + TimestampUtils.getFormatDate(endgxsh_endtime) + "'                              "); 
    }
    
    if (StringUtils.isNotEmpty(gxsh_user)) {
    	sb_sql.append(" AND " + SqlUtils.getInStr("gxsh_user", gxsh_user.split(","), true));
      }

    if(StringUtils.isNotEmpty(pregxfh_endtime) && StringUtils.isNotEmpty(endgxfh_endtime)) {
    	sb_sql.append(" AND gxfh_endtime BETWEEN '" + TimestampUtils.getFormatDate(pregxfh_endtime) + "' AND  ");
    	sb_sql.append(" '" + TimestampUtils.getFormatDate(endgxfh_endtime) + "'                              "); 
    }
    
    if (StringUtils.isNotEmpty(gxfh_user)) {
    	sb_sql.append(" AND " + SqlUtils.getInStr("gxfh_user", gxfh_user.split(","), true));
      }
    
    if (StringUtils.isNotEmpty(recbill_user)) {
    	sb_sql.append(" AND " + SqlUtils.getInStr("recbill_user", recbill_user.split(","), true));
      }
    
    if(StringUtils.isNotEmpty(prerecbill_time) && StringUtils.isNotEmpty(endrecbill_time)) {
    	sb_sql.append(" AND recbill_time BETWEEN '" + TimestampUtils.getFormatDate(prerecbill_time) + "' AND  ");
    	sb_sql.append(" '" + TimestampUtils.getFormatDate(endrecbill_time) + "'                              "); 
    }
    
    if(StringUtils.isNotEmpty(prebusi_auditdate) && StringUtils.isNotEmpty(endbusi_auditdate)) {
    	sb_sql.append(" AND busi_auditdate BETWEEN '" + TimestampUtils.getFormatDate(prebusi_auditdate) + "' AND  ");
    	sb_sql.append(" '" + TimestampUtils.getFormatDate(endbusi_auditdate) + "'                              "); 
    }
    
    if(StringUtils.isNotEmpty(preqz_endtime) && StringUtils.isNotEmpty(endqz_endtime)) {
    	sb_sql.append(" AND qz_endtime BETWEEN '" + TimestampUtils.getFormatDate(preqz_endtime) + "' AND  ");
    	sb_sql.append(" '" + TimestampUtils.getFormatDate(endqz_endtime) + "'                              "); 
    }
    
    if (StringUtils.isNotEmpty(qz_user)) {
    	sb_sql.append(" AND " + SqlUtils.getInStr("qz_user", qz_user.split(","), true));
      }
    
    if(StringUtils.isNotEmpty(prepaycomfirm_time) && StringUtils.isNotEmpty(endpaycomfirm_time)) {
    	sb_sql.append(" AND paycomfirm_time BETWEEN '" + TimestampUtils.getFormatDate(prepaycomfirm_time) + "' AND  ");
    	sb_sql.append(" '" + TimestampUtils.getFormatDate(endpaycomfirm_time) + "'                              "); 
    }
    
    
    if(StringUtils.isNotEmpty(prejs_endtime) && StringUtils.isNotEmpty(endjs_endtime)) {
    	sb_sql.append(" AND js_endtime BETWEEN '" + TimestampUtils.getFormatDate(prejs_endtime) + "' AND  ");
    	sb_sql.append(" '" + TimestampUtils.getFormatDate(endjs_endtime) + "'                              "); 
    }
    
    if (StringUtils.isNotEmpty(js_user)) {
    	sb_sql.append(" AND " + SqlUtils.getInStr("js_user", js_user.split(","), true));
     }
    
    sb_sql.append(" order by billdate ");
    List<SSCTaskReportDetailVO> sscTaskDetailReportVOs =  (List<SSCTaskReportDetailVO>) new BaseDAO().executeQuery(sb_sql.toString(), new BeanListProcessor(SSCTaskReportDetailVO.class));

    for (SSCTaskReportDetailVO sscTaskReportDetailVO : sscTaskDetailReportVOs) {
    	String billno = sscTaskReportDetailVO.getBillno();
    	SSCTaskReportDetailVO taskReportDetailVO = busiid_rel.get(billno);
    	sscTaskReportDetailVO.setBusiid(taskReportDetailVO.getBusiid());
    	sscTaskReportDetailVO.setTradetype_code(taskReportDetailVO.getTradetype_code());
    	sscTaskReportDetailVO.setPk_org_name(taskReportDetailVO.getPk_org_name());
    	sscTaskReportDetailVO.setTradetype_name(taskReportDetailVO.getTradetype_name());
	}
    
    return sscTaskDetailReportVOs;
    //add by sdan end 
    
//    return taskDetailReportVOs;
  }
  
  private void dropTempTable(ReportQueryConditionVO reportQueryConditionVO, String tableName) throws DAOException {
    StringBuilder sb = new StringBuilder("drop table " + tableName);
    (new BaseDAO()).executeUpdate(sb.toString());
  }
  
  private double integerToDouble(Object value) {
    return ((Integer)value).intValue() + 0.0D;
  }
  
  private double div(double cur, double per) {
    if (per == 0.0D)
      return 0.0D; 
    return cur / per;
  }
  
  private double increaseCpt(double cur, double per) {
    if (per == 0.0D)
      return 0.0D; 
    return (cur - per) * 100.0D / per;
  }
  
  private double add(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(Double.toString(v1));
    BigDecimal b2 = new BigDecimal(Double.toString(v2));
    return b1.add(b2).doubleValue();
  }
  
  private double add(String v1, String v2) {
    BigDecimal b1 = new BigDecimal(v1);
    BigDecimal b2 = new BigDecimal(v2);
    return b1.add(b2).doubleValue();
  }
  
  private double div(String v1, String v2) {
    BigDecimal b1 = new BigDecimal(v1);
    BigDecimal b2 = new BigDecimal(v2);
    return b1.subtract(b2).doubleValue();
  }
  
  private String caculateTime(String time, String timeUnit) {
    if (time.equals(""))
      return null; 
    BigDecimal timeD = new BigDecimal(time);
    if (BigDecimal.ZERO.equals(timeD))
      return BigDecimal.ZERO.toString(); 
    BigDecimal timeF = null;
    BigDecimal hour = new BigDecimal("3600");
    BigDecimal min = new BigDecimal("60");
    if (ReportQueryConditionVO.TIMEUNIT_HOUR.equals(timeUnit)) {
      timeF = timeD.divide(hour, 2, 4);
    } else {
      timeF = timeD.divide(min, 2, 4);
    } 
    return timeF.toString();
  }
  
  private String caculateMoney(String money, int digit) {
    BigDecimal Money = new BigDecimal(money);
    if (BigDecimal.ZERO.equals(Money))
      return BigDecimal.ZERO.toString(); 
    Money = Money.setScale(digit, 4);
    return Money.toString();
  }
  
  private static String createTempTable(String tablename, String columns, String idx) throws SQLException {
    Connection con = null;
    try {
      con = ConnectionFactory.getConnection();
      TempTable tt = new TempTable();
      tablename = tt.createTempTable(con, tablename, columns, new String[] { idx });
      RemoteProcessComponetFactory irc = (RemoteProcessComponetFactory)NCLocator.getInstance().lookup("RemoteProcessComponetFactory");
      String processname = TempTableCleaner.class.getName();
      RemoteProcessComponent threadScopePostProcess = irc.getThreadScopePostProcess(processname);
      if (threadScopePostProcess == null) {
        TempTableCleaner cleaner = new TempTableCleaner();
        cleaner.addTable(tablename);
        irc.addThreadScopePostProcess(processname, (RemoteProcessComponent)cleaner);
      } else if (threadScopePostProcess instanceof TempTableCleaner) {
        ((TempTableCleaner)threadScopePostProcess).addTable(tablename);
      } else {
        TempTableCleaner cleaner = new TempTableCleaner();
        cleaner.addTable(tablename);
        irc.addThreadScopePostProcess(processname + tablename, (RemoteProcessComponent)cleaner);
      } 
    } finally {
      try {
        if (con != null)
          con.close(); 
      } catch (Exception exception) {}
    } 
    return tablename;
  }
  
  private static String removeNull(String str) {
		if("0.00".equals(str) || str == null) {
			return "";
		}
	return str;
	  
}
}
