
package nccloud.impl.pub.ace;

import nccloud.bs.ic.ic.aggbusi.ace.bp.AceNccsynergyApproveBP;
import nccloud.bs.ic.ic.aggbusi.ace.bp.AceNccsynergyDeleteBP;
import nccloud.bs.ic.ic.aggbusi.ace.bp.AceNccsynergyInsertBP;
import nccloud.bs.ic.ic.aggbusi.ace.bp.AceNccsynergySendApproveBP;
import nccloud.bs.ic.ic.aggbusi.ace.bp.AceNccsynergyUnApproveBP;
import nccloud.bs.ic.ic.aggbusi.ace.bp.AceNccsynergyUnSendApproveBP;
import nccloud.bs.ic.ic.aggbusi.ace.bp.AceNccsynergyUpdateBP;
import nc.impl.pubapp.pattern.data.bill.BillLazyQuery;
import nc.impl.pubapp.pattern.data.bill.tool.BillTransferTool;
import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.vo.sap.syproconfig.AggSyProConfigVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

public abstract class AceAggbusiNccsynergyPubServiceImpl {
        // 新增
        public AggSyProConfigVO[] pubinsertBills(AggSyProConfigVO[] clientFullVOs,
                        AggSyProConfigVO[] originBills) throws BusinessException {
                try {
                        // 数据库中数据和前台传递过来的差异VO合并后的结果
                        BillTransferTool<AggSyProConfigVO> transferTool = new BillTransferTool<AggSyProConfigVO>(
                                        clientFullVOs);
                        // 调用BP
                        AceNccsynergyInsertBP action = new AceNccsynergyInsertBP();
                        AggSyProConfigVO[] retvos = action.insert(clientFullVOs);
                        // 构造返回数据
//                      return transferTool.getBillForToClient(retvos);
                        return retvos;
                } catch (Exception e) {
                        ExceptionUtils.marsh(e);
                }
                return null;
        }

        // 删除
        public void pubdeleteBills(AggSyProConfigVO[] clientFullVOs,
                        AggSyProConfigVO[] originBills) throws BusinessException {
                try {
                        // 调用BP
                        new AceNccsynergyDeleteBP().delete(clientFullVOs);
                } catch (Exception e) {
                        ExceptionUtils.marsh(e);
                }
        }

        // 修改
        public AggSyProConfigVO[] pubupdateBills(AggSyProConfigVO[] clientFullVOs,
                        AggSyProConfigVO[] originBills) throws BusinessException {
                try {
                        // 加锁 + 检查ts
                        BillTransferTool<AggSyProConfigVO> transferTool = new BillTransferTool<AggSyProConfigVO>(
                                        clientFullVOs);
                        AceNccsynergyUpdateBP bp = new AceNccsynergyUpdateBP();
                        AggSyProConfigVO[] retvos = bp.update(clientFullVOs, originBills);
                        // 构造返回数据
//                      return transferTool.getBillForToClient(retvos);
                        return retvos;
                } catch (Exception e) {
                        ExceptionUtils.marsh(e);
                }
                return null;
        }

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

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

        // 提交
        public AggSyProConfigVO[] pubsendapprovebills(
                        AggSyProConfigVO[] clientFullVOs, AggSyProConfigVO[] originBills)
                        throws BusinessException {
                AceNccsynergySendApproveBP bp = new AceNccsynergySendApproveBP();
                AggSyProConfigVO[] retvos = bp.sendApprove(clientFullVOs, originBills);
                return retvos;
        }

        // 收回
        public AggSyProConfigVO[] pubunsendapprovebills(
                        AggSyProConfigVO[] clientFullVOs, AggSyProConfigVO[] originBills)
                        throws BusinessException {
                AceNccsynergyUnSendApproveBP bp = new AceNccsynergyUnSendApproveBP();
                AggSyProConfigVO[] retvos = bp.unSend(clientFullVOs, originBills);
                return retvos;
        };

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

        // 弃审

        public AggSyProConfigVO[] pubunapprovebills(AggSyProConfigVO[] clientFullVOs,
                        AggSyProConfigVO[] originBills) throws BusinessException {
                for (int i = 0; clientFullVOs != null && i < clientFullVOs.length; i++) {
                        clientFullVOs[i].getParentVO().setStatus(VOStatus.UPDATED);
                }
                AceNccsynergyUnApproveBP bp = new AceNccsynergyUnApproveBP();
                AggSyProConfigVO[] retvos = bp.unApprove(clientFullVOs, originBills);
                return retvos;
        }

}