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

package nc.impl.mmpac.pickm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import nc.bs.mmpac.pickm.adapter.OnHandServiceAdapter;
import nc.bs.mmpac.pickm.adapter.OrgServiceAdapter;
import nc.bs.mmpac.pickm.adapter.TransTypeServiceAdapter;
import nc.bs.mmpac.pickm.bp.query.PickmQueryBillsByPKsBP;
import nc.bs.mmpac.pickm.bp.query.PickmQueryByBidsBP;
import nc.bs.mmpac.pickm.bp.query.PickmQueryByPermBP;
import nc.bs.mmpac.pickm.bp.query.PickmQueryBySchemeBP;
import nc.bs.mmpac.pickm.bp.query.PickmQueryByWhereSqlBP;
import nc.bs.mmpac.pickm.bp.query.PickmQueryItemsByPKsBP;
import nc.bs.mmpac.pickm.bp.query.PickmQueryMOInfoBP;
import nc.bs.mmpac.pickm.bp.query.PickmQueryMatSumPlanOutNumBP;
import nc.bs.mmpac.pickm.bp.query.PickmQueryMaterialVersionVOBP;
import nc.bs.mmpac.pickm.bp.query.PickmQueryRelationItemForHeadBP;
import nc.bs.mmpac.pickm.bp.query.PickmQuerySCOrderStockBP;
import nc.itf.mmpac.pickm.IPickmQueryService;
import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.util.mmf.busi.service.DeptPubService;
import nc.util.mmf.busi.service.OrgUnitPubService;
import nc.util.mmf.framework.base.MMStringUtil;
import nc.util.mmf.framework.base.MMValueCheck;
import nc.vo.bd.material.MaterialVersionVO;
import nc.vo.mmpac.pickm.entity.AggPickmVO;
import nc.vo.mmpac.pickm.entity.MaterialQueryCondition;
import nc.vo.mmpac.pickm.entity.MaterialRelationItem;
import nc.vo.mmpac.pickm.entity.PickmHeadVO;
import nc.vo.mmpac.pickm.entity.PickmItemVO;
import nc.vo.mmpac.pickm.entity.PickmTransTypeVO;
import nc.vo.mmpac.pickm.param.PickmParamForAdd;
import nc.vo.mmpac.pickm.param.PickmQueryMOParamForSetDelivery;
import nc.vo.mmpac.pickm.param.PickmTransParamForPlanReplace;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.pub.MapList;

public class PickmQueryServiceImpl implements IPickmQueryService {
    public PickmQueryServiceImpl() {
    }

    public Object[] queryByWhereSql(String whereSql, Class clazz, boolean lazyLoad, String[] orderPaths) throws BusinessException {
        try {
            PickmQueryByWhereSqlBP bp = new PickmQueryByWhereSqlBP();
            return bp.queryByWhereSql(whereSql, clazz, lazyLoad, orderPaths);
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public Object[] queryByWhereSql(String whereSql) throws BusinessException {
        try {
            PickmQueryByWhereSqlBP bp = new PickmQueryByWhereSqlBP();
            return bp.queryByWhereSql(whereSql);
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public AggPickmVO querySingleBillByPk(String primaryKey) throws BusinessException {
        try {
            AggPickmVO[] aggvos = this.queryBillsByPks(new String[]{primaryKey});
            return MMValueCheck.isEmpty(aggvos) ? null : aggvos[0];
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public AggPickmVO[] queryBillsByPks(String[] primaryKeys) throws BusinessException {
        try {
            PickmQueryBillsByPKsBP pickmQueryBillsByPKsBP = new PickmQueryBillsByPKsBP();
            return pickmQueryBillsByPKsBP.queryBillsByPks(primaryKeys);
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public MaterialRelationItem queryRelationItemForHead(MaterialQueryCondition condition) throws BusinessException {
        try {
            PickmQueryRelationItemForHeadBP bp = new PickmQueryRelationItemForHeadBP();
            return bp.queryRelationItemForHead(condition);
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public Map<String, MaterialVersionVO> queryMaterialVersionVOByPks(String[] pks) throws BusinessException {
        try {
            PickmQueryMaterialVersionVOBP bp = new PickmQueryMaterialVersionVOBP();
            return bp.getMaterialVersionVOByPks(pks);
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public AggPickmVO[] queryByQueryScheme(IQueryScheme queryScheme, Integer prodmode) throws BusinessException {
        try {
            PickmQueryBySchemeBP bp = new PickmQueryBySchemeBP();
            return bp.queryByQueryScheme(queryScheme, prodmode);
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public PickmItemVO queryPickmItemByPK(String pk) throws BusinessException {
        if (MMStringUtil.isEmpty(pk)) {
            return null;
        } else {
            PickmQueryItemsByPKsBP bp = new PickmQueryItemsByPKsBP();
            PickmItemVO[] itemVOs = null;

            try {
                itemVOs = bp.queryItemsByPks(new String[]{pk});
            } catch (Exception e) {
                ExceptionUtils.marsh(e);
            }

            return MMValueCheck.isEmpty(itemVOs) ? null : itemVOs[0];
        }
    }

    public Map<String, UFBoolean> queryHasDownFlowBill(String[] pks) throws BusinessException {
        return null;
    }

    public Map<String, Map<String, UFBoolean>> queryNeededData(AggPickmVO[] aggVOs) throws BusinessException {
        return null;
    }

    public AggPickmVO[] queryPermData(AggPickmVO[] aggVOs) throws BusinessException {
        return (new PickmQueryByPermBP()).queryByPerm(aggVOs);
    }

    public Map<String, Object[]> queryAcceptLowerData(PickmHeadVO headvo, PickmItemVO bodyvo) throws BusinessException {
        return null;
    }

    public Map<String, Object[]> queryUnAcceptLowerData(String cpickm_bid) throws BusinessException {
        return null;
    }

    public String querySCOrderStock(String sourceBillbid, String pk_group) throws BusinessException {
        try {
            PickmQuerySCOrderStockBP bp = new PickmQuerySCOrderStockBP();
            return bp.querySCOrderStock(sourceBillbid, pk_group);
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public Map<String, PickmQueryMOParamForSetDelivery> queryMOInfo(String[] ids, boolean isFromPMO) throws BusinessException {
        try {
            PickmQueryMOInfoBP bp = new PickmQueryMOInfoBP();
            return bp.queryMOInfo(ids, isFromPMO);
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public PickmTransParamForPlanReplace[] queryMatSumPlanOutNumFromSameFirstBill(PickmTransParamForPlanReplace[] queryParams) throws BusinessException {
        try {
            PickmQueryMatSumPlanOutNumBP bp = new PickmQueryMatSumPlanOutNumBP();
            return bp.queryMatSumPlanOutNumWithSameSource(queryParams);
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public Object[] queryPSCPickmByQueryScheme(IQueryScheme queryScheme) throws BusinessException {
        try {
            PickmQueryBySchemeBP bp = new PickmQueryBySchemeBP();
            return bp.queryPSCPickmByQueryScheme(queryScheme);
        } catch (Exception e) {
            ExceptionUtils.marsh(e);
            return null;
        }
    }

    public Map<String, UFBoolean> queryIsHavePSCitemsByRowIDs(String[] rowIDs) throws BusinessException {
        if (MMValueCheck.isEmpty(rowIDs)) {
            return null;
        } else {
            PickmQueryByBidsBP bp = new PickmQueryByBidsBP();
            return bp.getIsHavePSCitemByRowIDs(rowIDs);
        }
    }

    public Map<String, String> queryVidByOidForOrgAndDept(List<String> orgids, List<String> deptids) throws BusinessException {
        Map<String, String> result = new HashMap();
        if (MMValueCheck.isNotEmpty(orgids)) {
            Map<String, String> omap = OrgServiceAdapter.getOrgVIDsByOrgIDs((String[]) orgids.toArray(new String[0]));
            if (MMValueCheck.isNotEmpty(omap)) {
                for (String key : omap.keySet()) {
                    result.put("O" + key, (String) omap.get(key));
                }
            }
        }

        if (MMValueCheck.isNotEmpty(deptids)) {
            Map<String, String> dmap = DeptPubService.getIDeptPubService().getLastVIDSByDeptIDS((String[]) deptids.toArray(new String[0]));
            if (MMValueCheck.isNotEmpty(dmap)) {
                for (String key : dmap.keySet()) {
                    result.put("D" + key, (String) dmap.get(key));
                }
            }
        }

        return result;
    }

    public PickmParamForAdd queryOrgvidAndTransinfForAdd(String pk_org, String pk_group) throws BusinessException {
        PickmParamForAdd param = new PickmParamForAdd();
        if (MMValueCheck.isNotEmpty(pk_org)) {
            String pk_org_v = OrgUnitPubService.getNewVIDByOrgID(pk_org);
            param.setPk_org_v(pk_org_v);
        }

        if (MMValueCheck.isNotEmpty(pk_group)) {
            StringBuffer wherePart = new StringBuffer();
            wherePart.append(" and fpickmtype=1");
            wherePart.append(" and pk_group='");
            wherePart.append(pk_group);
            wherePart.append("'");
            wherePart.append(" and ctrantypeid in (select pk_billtypeid from bd_billtype  where parentbilltype = '55A3' and islock='N')");

            try {
                PickmTransTypeVO[] transVOs = TransTypeServiceAdapter.queryTranstypeExtProp(wherePart.toString());
                if (MMValueCheck.isNotEmpty(transVOs) && MMValueCheck.isNotEmpty(transVOs[0])) {
                    param.setTransID(transVOs[0].getCtrantypeid());
                    param.setTransCode(transVOs[0].getVtrantypecode());
                }
            } catch (Exception e) {
                ExceptionUtils.wrappException(e);
            }

            return param;
        } else {
            return null;
        }
    }

    public PickmHeadVO[] queryHeadByIds(String[] cpickmids) throws BusinessException {
        if (MMValueCheck.isEmpty(cpickmids)) {
            return null;
        } else {
            try {
                PickmQueryByBidsBP bp = new PickmQueryByBidsBP();
                return bp.queryByHeadIDs(cpickmids);
            } catch (Exception e) {
                ExceptionUtils.marsh(e);
                return null;
            }
        }
    }

    public PickmItemVO[] queryCLItemsForNcc(String cpickmid, String[] cpickmbids) throws BusinessException {
        PickmItemVO[] items = null;
        PickmQueryItemsByPKsBP queryBP = new PickmQueryItemsByPKsBP();
        if (MMValueCheck.isEmpty(cpickmid)) {
            items = queryBP.queryItemsByPks(cpickmbids);
        } else {
            items = queryBP.queryItemsByHeadPks(new String[]{cpickmid});
        }

        return MMValueCheck.isEmpty(items) ? null : this.fillCLItemsForNcc(items);
    }

    public AggPickmVO[] queryAggPickmVObyBid(String[] cpickmbids) throws BusinessException {
        PickmQueryByBidsBP bp = new PickmQueryByBidsBP();
        return bp.queryAggPickmVObyBids(cpickmbids);
    }

    public PickmItemVO[] fillCLItemsForNcc(PickmItemVO[] items) throws BusinessException {
        return OnHandServiceAdapter.fillCLItemsForNcc(items);
    }

    public MapList<String, PickmItemVO> getReplaceGroupItemByKeyID(String[] bids, String hid) throws BusinessException {
        PickmQueryByBidsBP bp = new PickmQueryByBidsBP();
        return bp.getReplaceGroupItemByKeyID(bids, hid);
    }

    public PickmItemVO[] queryItemsByIds(String[] itemIds) throws BusinessException {
        if (MMValueCheck.isEmpty(itemIds)) {
            return null;
        } else {
            try {
                PickmQueryItemsByPKsBP queryBP = new PickmQueryItemsByPKsBP();
                return queryBP.queryItemsByPks(itemIds);
            } catch (Exception e) {
                ExceptionUtils.marsh(e);
                return null;
            }
        }

    }
}
