package com.jzdsh.auto.app.controller.admin.mvalidator;

import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.validate.Validator;
import com.jzdsh.auto.model.HelpInfo;

/**
 * @ProjectName: auto
 * @Package: com.jzdsh.auto.app.controller.admin.mvalidator
 * @ClassName: AdminhelpInfoValidator
 * @Author: Jzdsh
 * @Description:
 * @Date: 2020/3/27 19:17
 * @Version: 1.0
 */
public class AdminHelpInfoValidator extends Validator {
    @Override
    protected void validate(Controller c) {
        setShortCircuit(true);
        setRet(Ret.fail( ));
        c.getFile();
        String title = c.get("helpInfo.title");
        Integer type = c.getInt("helpInfo.typeId");
        String sort = c.get("helpInfo.sort");
        String info = c.get("helpInfo.info");
        if (title == null) {
            addError("msg", "帮助中心   请填写标题!");
        }
        if (title.length( ) > 49) {
            addError("msg", "帮助中心 标题太长!");
        }
        if (type == null) {
            addError("msg", "帮助中心   请选择类型!");
        }
        if (info == null || info.length( ) < 20) {
            addError("msg", "帮助中心   详情内容太少了点吧");
        }
        String reg = "^[0-9]{1,4}$";
        if (!sort.matches(reg)) {
            addError("msg", "帮助中心 排序只允许1-4位数字!");
        }
    }

    @Override
    protected void handleError(Controller c) {
        c.keepModel(HelpInfo.class);
        c.renderJson(getRet( ));
    }
}
