package fi.cas.form;

import com.alibaba.druid.util.StringUtils;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.entity.operate.result.IOperateInfo;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.form.events.AfterDoOperationEventArgs;

import java.util.List;

public class AgentPayBillEditPlugin extends AbstractBillPlugIn {
    public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
        super.afterDoOperation(afterDoOperationEventArgs);

        String opKey = afterDoOperationEventArgs.getOperateKey();

        if(StringUtils.equals("sendtojhx", opKey)){
            OperationResult operationResult = afterDoOperationEventArgs.getOperationResult();
            operationResult.setShowMessage(false);

            String message = operationResult.getMessage();

            if(!StringUtils.isEmpty(message) && message.contains("推送资金系统成功")){
                this.getView().showSuccessNotification(message);
                this.getView().invokeOperation("refresh");
            } else {
                List<IOperateInfo> errorInfos = operationResult.getAllErrorOrValidateInfo();
                boolean isSuccess = operationResult.isSuccess();
                if (errorInfos.size() > 0) {
                    operationResult.setSuccess(false);
                    StringBuffer msg = new StringBuffer();
                    for (IOperateInfo errInfo : errorInfos) {
                        msg.append(errInfo.getMessage()).append("\r\n");
                    }
                    message = message + "\r\n" + msg.toString();
                }

                if (!StringUtils.isEmpty(message)) {
                    this.getView().showErrorNotification(message);
                }
            }
        }
    }
}
