package cc.smtweb.framework.core.mvc.service;

import cc.smtweb.framework.core.common.R;

/**
 * Created by Akmm at 2022/3/2 19:44
 */
@Deprecated
public abstract class AbstractLoadHandler<T> extends AbstractHandler {

    public R load() {
        long id = readId();
        T bean;
        if (id <= 0L) {
            bean = createComp();
        } else {
            bean = loadComp(id);
        }
        return R.success(bean);
    }

    /**
     * 读取页面传回来的id
     *
     * @return
     */
    protected long readId() {
        return params.readLong("id", 0L);
    }

    protected abstract T createComp();

    protected abstract T loadComp(long id);
}
