package com.mosty.base.annot.validation;

import com.mosty.base.annot.IsRybq;
import com.mosty.base.utils.DictUtils;
import com.mosty.base.utils.spring.SpringValidUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author zhangzhao
 * @description 校验是否是人员标签 实现类
 * @modifier zhangzhao
 * @modifiedTime 2023/3/18 14:07
 * @since 2023/3/18 14:07
 */
public class RybqValidation implements ConstraintValidator<IsRybq, Object> {

    private IsRybq annotation;

    @Override
    public void initialize(IsRybq constraintAnnotation) {
        this.annotation = constraintAnnotation;
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext constraintValidatorContext) {
        String valueStr = value + "";

        //校验人员标签长度是否合规
        boolean isSizeValidation = SpringValidUtils.annotationSizeValidation(annotation.isNotBlank(), annotation.max(), annotation.min(), valueStr);
        if(!isSizeValidation){
            return false;
        }

        //使用字典工具类中的校验方法
        return DictUtils.isDictContainValues(DictUtils.DICT_ZDBH_D_BZ_RYBQ, value + "");
    }

}
