package nc.impl.pub.ace;

import nc.bs.hr.baod_orders.ace.bp.AceBaod_ordersDeleteBP;
import nc.bs.hr.baod_orders.ace.bp.AceBaod_ordersInsertBP;
import nc.bs.hr.baod_orders.ace.bp.AceBaod_ordersUpdateBP;
import nc.bs.hr.baod_orders.ace.bp.AceBaod_ordersSendApproveBP;
import nc.bs.hr.baod_orders.ace.bp.AceBaod_ordersUnSendApproveBP;
import nc.bs.hr.baod_orders.ace.bp.AceBaod_ordersApproveBP;
import nc.bs.hr.baod_orders.ace.bp.AceBaod_ordersUnApproveBP;
import nc.impl.pubapp.pattern.data.bill.tool.BillTransferTool;
		import nc.vo.th.baod.entity.AggBaodVO;
import nc.impl.pubapp.pattern.data.bill.BillLazyQuery;
import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.query2.sql.process.QuerySchemeProcessor;
import nc.impl.pubapp.pattern.database.DataAccessUtils;
		import nc.vo.pubapp.pattern.data.IRowSet;
import nc.vo.pubapp.bill.pagination.PaginationTransferObject;
import nc.vo.pubapp.bill.pagination.util.PaginationUtils;
import nc.impl.pubapp.pattern.data.bill.BillQuery;

public abstract class AceBaod_ordersPubServiceImpl {
		    //新增
    public AggBaodVO[] pubinsertBills(AggBaodVO[] clientFullVOs,AggBaodVO[] originBills) throws BusinessException {
        try {
          // 数据库中数据和前台传递过来的差异VO合并后的结果
          BillTransferTool<AggBaodVO> transferTool =new BillTransferTool<AggBaodVO>(clientFullVOs);
          // 调用BP
          AceBaod_ordersInsertBP action = new AceBaod_ordersInsertBP();
          AggBaodVO[] retvos = action.insert(clientFullVOs);
          // 构造返回数据
          return transferTool.getBillForToClient(retvos);
        }catch (Exception e) {
          ExceptionUtils.marsh(e);
        }
        return null;
    }
    //删除
				    public void pubdeleteBills(AggBaodVO[] clientFullVOs,AggBaodVO[] originBills) throws BusinessException {
				        try {
				          // 调用BP
				          new AceBaod_ordersDeleteBP().delete(clientFullVOs);
				        } catch (Exception e) {
				          ExceptionUtils.marsh(e);
				        }
				    }
				    //修改
				    public AggBaodVO				[] pubupdateBills(AggBaodVO[] clientFullVOs,AggBaodVO[] originBills) throws BusinessException {
				        try {
				          //加锁 + 检查ts
				          BillTransferTool<AggBaodVO				> transferTool =new BillTransferTool<AggBaodVO>(clientFullVOs);
				          AceBaod_ordersUpdateBP bp = new AceBaod_ordersUpdateBP();
				          AggBaodVO[] retvos = bp.update(clientFullVOs, originBills);
				          // 构造返回数据
				          return transferTool.getBillForToClient(retvos);
				        }catch (Exception e) {
				          ExceptionUtils.marsh(e);
        }
				          return null;
  				  }


  public AggBaodVO[] pubquerybills(IQueryScheme queryScheme)
      throws BusinessException {
    AggBaodVO[] bills = null;
    try {
      this.preQuery(queryScheme);
      BillLazyQuery<AggBaodVO> query =
          new BillLazyQuery<AggBaodVO>(AggBaodVO.class);
      bills = query.query(queryScheme, null);
    }
    catch (Exception e) {
      ExceptionUtils.marsh(e);
    }
    return bills;
  }

	  /**
   * 由子类实现，查询之前对queryScheme进行加工，加入自己的逻辑
   * 
   * @param queryScheme
   */
  protected void preQuery(IQueryScheme queryScheme) {
    // 查询之前对queryScheme进行加工，加入自己的逻辑
  }


		  //提交
				  public AggBaodVO[] pubsendapprovebills(AggBaodVO[] clientFullVOs,AggBaodVO[] originBills) 
				      throws BusinessException {
				    AceBaod_ordersSendApproveBP bp = new AceBaod_ordersSendApproveBP();
				    AggBaodVO[] retvos = bp.sendApprove(clientFullVOs, originBills);
				    return retvos;
				  }
				  
				  //收回
				  public AggBaodVO[] pubunsendapprovebills(AggBaodVO[] clientFullVOs,AggBaodVO[] originBills) 
				      throws BusinessException {
				    AceBaod_ordersUnSendApproveBP bp = new AceBaod_ordersUnSendApproveBP();
				    AggBaodVO[] retvos = bp.unSend(clientFullVOs, originBills);
				    return retvos;
				  };

  //审批
				  public AggBaodVO[] pubapprovebills(AggBaodVO[] clientFullVOs,AggBaodVO[] originBills) 
				      throws BusinessException {
				    for (int i = 0; clientFullVOs != null && i < clientFullVOs.length; i++) {
				      clientFullVOs[i].getParentVO().setStatus(VOStatus.UPDATED);
				    }
				    AceBaod_ordersApproveBP bp = new AceBaod_ordersApproveBP();
				    AggBaodVO[] retvos = bp.approve(clientFullVOs, originBills);
				    return retvos;
				  }
				  
				  //弃审
				
				  public AggBaodVO[] pubunapprovebills(AggBaodVO[] clientFullVOs,AggBaodVO[] originBills)
				      throws BusinessException {
    				for (int i = 0; clientFullVOs != null && i < clientFullVOs.length; i++) {
				      clientFullVOs[i].getParentVO().setStatus(VOStatus.UPDATED);
				    }
				    AceBaod_ordersUnApproveBP bp = new AceBaod_ordersUnApproveBP();
				    AggBaodVO[] retvos = bp.unApprove(clientFullVOs, originBills);
				    return retvos;
				  }
				  
				
}