package nckd.jimin.jyyy.bd.plugin.msg.ecology;

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 EcologyListPlugin extends AbstractBillPlugIn {
    @Override
    public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
        super.afterDoOperation(afterDoOperationEventArgs);

        if(StringUtils.equals("sendmsg",afterDoOperationEventArgs.getOperateKey())){
            OperationResult operationResult = afterDoOperationEventArgs.getOperationResult();
            operationResult.setShowMessage(false);
            String message = operationResult.getMessage();

            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);
            } else {
                this.getView().showTipNotification("所选记录不需要重发！");
            }
        }
    }
}
