package nc.impl.pub.ace;

import nc.bs.th.th_bonus.ace.bp.AceTh_bonusDeleteBP;
import nc.bs.th.th_bonus.ace.bp.AceTh_bonusInsertBP;
import nc.bs.th.th_bonus.ace.bp.AceTh_bonusUpdateBP;
import nc.impl.pubapp.pattern.data.bill.tool.BillTransferTool;
		import nc.vo.th.bonus.AggbonusVO;
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 AceTh_bonusPubServiceImpl {
    //新增
    public AggbonusVO[] pubinsertBills(AggbonusVO[] vos) throws BusinessException {
        try {
          // 数据库中数据和前台传递过来的差异VO合并后的结果
          BillTransferTool<AggbonusVO> transferTool =new BillTransferTool<AggbonusVO>(vos);
          AggbonusVO[] mergedVO = transferTool.getClientFullInfoBill();

          // 调用BP
          AceTh_bonusInsertBP action = new AceTh_bonusInsertBP();
          AggbonusVO[] retvos = action.insert(mergedVO);
          // 构造返回数据
          return transferTool.getBillForToClient(retvos);
        }catch (Exception e) {
          ExceptionUtils.marsh(e);
        }
        return null;
    }
    //删除
    public void pubdeleteBills(AggbonusVO[] vos) throws BusinessException {
        try {
			          // 加锁 比较ts
          BillTransferTool<AggbonusVO> transferTool = new BillTransferTool<AggbonusVO>(vos);
          AggbonusVO[] fullBills = transferTool.getClientFullInfoBill();
          AceTh_bonusDeleteBP deleteBP = new AceTh_bonusDeleteBP();
          deleteBP.delete(fullBills);
        }catch (Exception e) {
          ExceptionUtils.marsh(e);
        }
    }
  	  //修改
    public AggbonusVO[] pubupdateBills(AggbonusVO[] vos) throws BusinessException {
        try {
    	      //加锁 + 检查ts
		          BillTransferTool<AggbonusVO> transTool = new BillTransferTool<AggbonusVO>(vos);
		          //补全前台VO
          AggbonusVO[] fullBills = transTool.getClientFullInfoBill();
	          //获得修改前vo
          AggbonusVO[] originBills = transTool.getOriginBills();
          // 调用BP
          AceTh_bonusUpdateBP bp = new AceTh_bonusUpdateBP();
          AggbonusVO[] retBills = bp.update(fullBills, originBills);
          // 构造返回数据
          retBills = transTool.getBillForToClient(retBills);
          return retBills;
        }catch (Exception e) {
          ExceptionUtils.marsh(e);
        }
          return null;
     }


  //分页查询方法，查询所有PK
  public String[] pubquerypkbills(IQueryScheme queryScheme)
      throws BusinessException {
    // String beanId=(String) queryScheme.get(QueryConstants.BEAN_ID);
    StringBuffer sql = new StringBuffer();
    QuerySchemeProcessor processor = new QuerySchemeProcessor(queryScheme);
    String mainAlias = processor.getMainTableAlias();
    sql.append(" select distinct ");
    sql.append(mainAlias);
    sql.append(".");
    sql.append("pk_bonus");
    sql.append(processor.getFinalFromWhere());
    DataAccessUtils dao = new DataAccessUtils();
    IRowSet rowset = dao.query(sql.toString());
    String[] keys = rowset.toOneDimensionStringArray();
    return keys;
  }
  
  //分页查询方法，根据PK查单据
  public AggbonusVO[] pubquerybillbypkbills(String[] pks)
      throws BusinessException {
    AggbonusVO[] bills = null;
    BillQuery<AggbonusVO> query =
        new BillQuery<AggbonusVO>(AggbonusVO.class);
    bills = query.query(pks);
    return PaginationUtils.filterNotExistBills(bills, pks);
  }

				
}