package nckd.jxccl.hr.psms.plugin.form.performance;

import kd.bos.form.MessageBoxOptions;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.sdk.plugin.Plugin;
import nckd.jxccl.base.common.constant.FormConstant;
import nckd.jxccl.hr.psms.common.PositionStructureConstant;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
* 年度绩效排名管理列表插件
* 实体标识：nckd_perfrankmgmtentry
* @author W.Y.C
* @date 2025/10/31 10:16
* @version 1.0
*/
public class PerfrankMgmtListPlugin extends AbstractListPlugin implements Plugin {

    @Override
    public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
        String operateKey = afterDoOperationEventArgs.getOperateKey();
        boolean success = afterDoOperationEventArgs.getOperationResult() != null && afterDoOperationEventArgs.getOperationResult().isSuccess();
        if(success){
            if(PositionStructureConstant.ISLOCKED_OP.equalsIgnoreCase(operateKey)){
                Map<String, String> customData = afterDoOperationEventArgs.getOperationResult().getCustomData();
                String message = customData.get("message");
                if(StringUtils.isNotBlank( message)){
                    this.getView().showConfirm("提示","锁定成功！",message, MessageBoxOptions.OK,null,null,null,null);
                }else{
                    this.getView().showSuccessNotification("锁定成功！");
                }
                this.getView().invokeOperation(FormConstant.REFRESH_OP);
            }else if(PositionStructureConstant.UNLOCKED_OP.equalsIgnoreCase(operateKey)){
                Map<String, String> customData = afterDoOperationEventArgs.getOperationResult().getCustomData();
                if(customData != null && customData.containsKey("message")){
                    String message = customData.get("message");
                    if(StringUtils.isNotBlank( message)){
                        this.getView().showConfirm("提示","解锁成功！",message, MessageBoxOptions.OK,null,null,null,null);
                    }else{
                        this.getView().showSuccessNotification("解锁成功！");
                    }
                    this.getView().invokeOperation(FormConstant.REFRESH_OP);
                }else{
                    this.getView().showSuccessNotification("发起流程成功，待审批通过后自动解锁！");
                }
            }
        }

    }
}