//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nccloud.api.so.so.UpCloses;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import nc.bs.framework.common.NCLocator;
import nc.itf.so.m30.closemanage.ISaleOrderCloseManageMaintain;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.scmpub.util.CombineViewToAggUtil;
import nc.vo.scmpub.util.SagasUtil;
import nc.vo.so.m30.entity.SaleOrderBVO;
import nc.vo.so.m30.entity.SaleOrderHVO;
import nc.vo.so.m30.entity.SaleOrderVO;
import nc.vo.so.m30.entity.SaleOrderViewVO;
import nc.vo.so.m30.util.SaleOrderStateContext;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.ui.pattern.grid.Grid;
import nccloud.pubitf.scmpub.pub.batchopr.dto.ISCMBatchOprContext;
import nccloud.pubitf.scmpub.pub.batchopr.dto.SCMBatchOprContext;
import nccloud.pubitf.scmpub.pub.batchopr.dto.SCMBatchResultDTO;
import nccloud.pubitf.so.saleorderclose.service.IQuerySaleOrderCloseService;
import nccloud.pubitf.so.saleorderclose.service.ISaleOrderCloseMaintainService;
import nccloud.pubitf.so.saleorderclose.utils.SaleOrderCloseUtils;
import nccloud.util.so.TransBillUtil;
import nccloud.web.scmpub.pub.operator.SCMGridOperator;
import nccloud.web.scmpub.pub.utils.SCMBatchOperatorResult;
import nccloud.web.scmpub.pub.utils.batchopr.SCMBatchOperator;
import nccloud.web.scmpub.pub.utils.compare.SCMCompareUtil;
import nccloud.web.scmpub.vocheck.VOSagaFrozenCheck;
import nccloud.web.so.pub.batchopr.SOBatchOprResultViewConvertor;
import nccloud.web.so.pub.scale.SaleOrderViewScaleProcess;
import nccloud.web.so.saleorderclose.entity.SaleOrderCloseInfo;

public class SaleOrderCloseUtil {
    private static String[] operateByVO = new String[]{"billClose", "billOpen"};

    public SaleOrderCloseUtil() {
    }

    public static SaleOrderViewVO[] buttonClick(SaleOrderCloseInfo combineinfo, String buttonType) throws BusinessException {
        SaleOrderViewVO[] vos = queryViewByBIDs(combineinfo.getBids(), combineinfo.getVclosereason());
        CombineViewToAggUtil<SaleOrderVO> combineViewToAggUtil = new CombineViewToAggUtil(SaleOrderVO.class, SaleOrderHVO.class, SaleOrderBVO.class);
        SaleOrderVO[] bills = (SaleOrderVO[])combineViewToAggUtil.combineViewToAgg(vos, "csaleorderid");
        VOSagaFrozenCheck checkVo = new VOSagaFrozenCheck(true, "csaleorderid");
        checkVo.processCheck(bills);
        ISaleOrderCloseMaintainService service=NCLocator.getInstance()
                .lookup(ISaleOrderCloseMaintainService.class);
        SaleOrderViewVO[] saleOrderViewVOS= service.billOpen(bills,false);
        return saleOrderViewVOS;
    }

    public static SaleOrderViewVO[] queryViewByBIDs(String[] bidts, String vclosereason) throws BusinessException {
        Map<String, UFDateTime> bid_ts = new HashMap();
        String[] bids = TransBillUtil.splitBidts(bidts, bid_ts);
        IQuerySaleOrderCloseService service = NCLocator.getInstance()
                .lookup(IQuerySaleOrderCloseService.class);
        SaleOrderViewVO[] vos = service.queryByIds(bids);
        TransBillUtil.fillBodyTs(vos, "csaleorderbid", bid_ts);
        SaleOrderCloseUtils.setCloseOpenReason(vos, vclosereason);
        return vos;
    }
}
