package com.huatek.busi.common.valid;

import java.util.List;
import java.util.Map;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import com.huatek.busi.common.util.BusiResultUtil;
import com.huatek.torch.frame.tools.ConstantUtil;

/**
 * 后台输入参数校验工具类
 * 
 * @author anker_cheng
 * @date 2019/09/06
 */
public final class ValidUtil {

    private ValidUtil() {}

    public static Map<String, Object> validError(BindingResult result) {
        List<FieldError> list = result.getFieldErrors();
        StringBuilder errorMsg = new StringBuilder();
        for (FieldError error : list) {
            if (errorMsg.length() > 0) {
                errorMsg.append("；");
            }
            errorMsg.append(error.getDefaultMessage());
        }
        return BusiResultUtil.put(ConstantUtil.REQUEST_FAIL, errorMsg.toString(), null);
    }
}
