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

package nccloud.impl.imag.service.bp;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.pf.pub.PfDataCache;
import nc.imag.common.util.ImagePubUtil;
import nc.imag.common.util.ImageServiceCommonUtil;
import nc.imag.imag.exception.BillInfoCheckBusinessException;
import nc.imag.imag.exception.ImagConfigBusinessException;
import nc.imag.imag.exception.ImagStateCheckBusinessException;
import nc.imag.itf.service.IImageService;
import nc.imag.pub.util.ImageServiceUtil;
import nc.imag.util.ws.ImageFactoryConfigUtil;
import nc.imag.util.ws.ImageFlowUtil;
import nc.imag.util.ws.ImageLookupExternalInstance;
import nc.vo.image.log.ImageLogBusiTypeEnum;
import nc.vo.image.log.ImageLogRequest;
import nc.vo.image.log.ImageLogUtil;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pub.BusinessException;
import nccloud.itf.imag.service.bp.ISSCImageCheckBP;
import nccloud.itf.imag.service.bp.ISSCImageExtendBP;

public class SSCImageCheckBPImpl implements ISSCImageCheckBP {
    public SSCImageCheckBPImpl() {
    }

    public void commitCheckWithImage(String billType, String billID, String pk_org) throws BusinessException {
        int scanType = ImageServiceCommonUtil.getImageScanType(pk_org, billType);
        if (scanType != 0 && scanType != -2) {
            if (billID != null && !billID.equals("")) {
                String factoryCode = ImageFactoryConfigUtil.getFactoryCode((String)null);
                if (factoryCode == null) {
                    factoryCode = ImageServiceCommonUtil.getImageFactoryCode(pk_org);
                }

                boolean scanInflow = ImageServiceCommonUtil.getIfScanInFlow(pk_org, billType);
                boolean ifinflow = ImageFlowUtil.billIsInFlow(billID);
                boolean ifimageact = ImageFlowUtil.isWFOnImageActivity(billID);
                int imagestate = ((IImageService)NCLocator.getInstance().lookup(IImageService.class)).getImageState(billID);
                ISSCImageExtendBP realExtendBP = new SSCImageExtendBPImpl();
                switch (scanType) {
                    case -2:
                        return;
                    case -1:
                    case 0:
                        if (imagestate != 1 && imagestate != 5 && imagestate <= 6 && (!ifinflow || ImageFlowUtil.ifMakeBillActive(billID))) {
                            Map<String, List<String>> imageNum = null;

                            try {
                                imageNum = realExtendBP.downloadImages(Arrays.asList(billID));
                            } catch (Exception var14) {
                                if (var14.getMessage() != null && "调用影像服务异常提示：null".equals(var14.getMessage())) {
                                    throw new ImagStateCheckBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1054004002_0", "01054004002-0035"));
                                }

                                throw new ImagStateCheckBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1054003_0", "01054003-0073" + var14.getMessage()));
                            }

                            if (imageNum != null && imageNum.size() > 0) {
                                throw new ImagStateCheckBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1054003_0", "01054003-0071"));
                            }

                            String userid = InvocationInfoProxy.getInstance().getUserId();
                            ImageLogRequest request = new ImageLogRequest(billID, userid, (Object)null);
                            ImageLogUtil.insertMainLog(ImageLogBusiTypeEnum.DELETE_UNSCANIMAGETASK_MAKEBILL, request, (Object)null);
                            ImageServiceUtil.deleteImageOnSync(new String[]{billID}, userid, NCLangRes4VoTransl.getNCLangRes().getStrByID("1054003002_0", "01054003002-0026"));
                        }

                        return;
                    case 1:
                        if (!ImageServiceCommonUtil.ifImageHasScaned(billID, pk_org)) {
                            String billtypeName = PfDataCache.getBillTypeInfo(billType).getBilltypenameOfCurrLang();
                            throw new ImagStateCheckBusinessException(billtypeName + NCLangRes4VoTransl.getNCLangRes().getStrByID("1054003_0", "01054003-0065"));
                        } else {
                            Map<String, List<String>> imageNumMap = realExtendBP.downloadImages(Arrays.asList(billID));
                            if (imageNumMap != null && imageNumMap.size() != 0) {
                                return;
                            }

                            throw new ImagStateCheckBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1054003_0", "01054003-0072"));
                        }
                    case 2:
                        if (scanInflow) {
                            if (!ifimageact) {
                                return;
                            } else if (!ImageServiceCommonUtil.ifImageHasScaned(billID, pk_org)) {
                                throw new ImagStateCheckBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1054003_0", "01054003-0066"));
                            }
                        } else if (ifinflow) {
                            return;
                        } else if (!ImageServiceCommonUtil.ifImageHasScaned(billID, pk_org)) {
                            String billtypeName = PfDataCache.getBillTypeInfo(billType).getBilltypenameOfCurrLang();
                            throw new ImagStateCheckBusinessException(billtypeName + NCLangRes4VoTransl.getNCLangRes().getStrByID("1054003_0", "01054003-0065"));
                        }
                    default:
                        (new ImageLookupExternalInstance()).CusCommitCheckWithImage(billType, billID, pk_org, ifinflow, ifimageact, imagestate, scanType, factoryCode);
                }
            } else {
                throw new BillInfoCheckBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1054003_0", "01054003-0018"));
            }
        }
    }

    public int getImageShowPermission(String billType, String billId) throws BusinessException {
        return ImagePubUtil.getImageShowPermission2(billType, billId);
    }

    public int getImageShowPermission(Object billvo, String billType, String billId, String pk_org) throws BusinessException {
        return ImagePubUtil.getImageShowPermission2(billvo, billType, billId, pk_org);
    }

    public void imageShowCheck(String billType, String billID) throws BusinessException {
        ImagePubUtil.checkImageIsUsedAndBillIDEmpty(billID, InvocationInfoProxy.getInstance().getGroupId());
    }

    public void checkCusImageScanck(Object billvo, String billtypeCode, String transtypeCode, String billID, String pk_org, String userid, Object other) throws BusinessException {
        if (billID != null && ImageServiceCommonUtil.ifImageHasScaned(billID, pk_org)) {
            throw new ImagStateCheckBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1054003_0", "01054003-0056"));
        } else {
            int scanType = ImageServiceCommonUtil.getImageScanType(pk_org, transtypeCode);
            if (scanType == 0) {
                throw new ImagConfigBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1054003_0", "01054003-0022"));
            }
        }
    }
}
