package nckd.jimin.jyyy.fi.plugin.form;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.fi.cas.util.EmptyUtil;

import java.io.IOException;

/**
 * 费用报销类单据联查电子回单批量
 * @author wanghaiwu_kd
 * @date 2025/09/04
 */
public class FeiBillFileViewMultEditPlugin extends AbstractBillPlugIn {
    private static final Log logger = LogFactory.getLog(FeiBillFileViewMultEditPlugin.class);

    @Override
    public void afterDoOperation(AfterDoOperationEventArgs e) {
        super.afterDoOperation(e);
        String opKey = e.getOperateKey();

        if ("nckd_multelecreceipt".equalsIgnoreCase(opKey)) {

            Object selectId = this.getModel().getValue("id");

            OperationResult operationResult = e.getOperationResult();
            if (operationResult.isSuccess()) {
                logger.info("-- 报销单联查电子回单附件开始 --");

                if(EmptyUtil.isNoEmpty(selectId) && Long.valueOf(selectId.toString()) > 0){
                    String pdfUrl = null;
                    try {
                        pdfUrl = FeiBillFileViewMultHelper.getElecreceiptByFile(selectId.toString());
                    } catch (IOException ex) {
                        throw new RuntimeException(ex);
                    }

                    if (kd.bos.util.StringUtils.isNotEmpty(pdfUrl)) {
                        FeiBillFileViewMultHelper.openForm(this.getView(), pdfUrl);
                    } else {
                        this.getView().showSuccessNotification("没有相应的电子回单！");
                    }
                }
            }
        }
    }





}
