Search in sources :

Example 1 with SelectHelper

use of app.hongs.action.SelectHelper in project HongsCORE by ihongs.

the class DataAction method list.

@Action("revert/search")
public void list(ActionHelper helper) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    String ent = runner.getEntity();
    String mod = runner.getModule();
    Data sr = (Data) getEntity(helper);
    Model mo = sr.getModel();
    Map rd = helper.getRequestData();
    rd.remove("user_id");
    rd.put("form_id", sr.getFormId());
    Map sd = mo.search(rd);
    // 详情数据转换
    if (sd.containsKey("info")) {
        Map df = (Map) sd.remove("info");
        Map dt = (Map) app.hongs.util.Data.toObject((String) df.remove("data"));
        sd.put("logs", df);
        sd.put("info", dt);
        // 补充枚举和关联
        Set ab = Synt.toTerms(rd.get(Cnst.AB_KEY));
        if (ab != null) {
            byte md = 0;
            if (ab.contains("_enum")) {
                md += 2;
            }
            if (ab.contains("_time")) {
                md += 4;
            }
            if (ab.contains("_link")) {
                md += 8;
            }
            if (md != 0) {
                new SelectHelper().addItemsByForm(mod, ent).select(sd, md);
            }
            if (ab.contains("_fork")) {
                new SpreadHelper().addItemsByForm(mod, ent).spread(sd);
            }
        }
    }
    helper.reply(sd);
}
Also used : ActionRunner(app.hongs.action.ActionRunner) FormSet(app.hongs.action.FormSet) Set(java.util.Set) Model(app.hongs.db.Model) Data(app.hongs.serv.matrix.Data) SpreadHelper(app.hongs.action.SpreadHelper) HashMap(java.util.HashMap) Map(java.util.Map) SelectHelper(app.hongs.action.SelectHelper) Action(app.hongs.action.anno.Action) SearchAction(app.hongs.dh.search.SearchAction)

Example 2 with SelectHelper

use of app.hongs.action.SelectHelper in project HongsCORE by ihongs.

the class SelectInvoker method invoke.

@Override
public void invoke(ActionHelper helper, ActionRunner chains, Annotation anno) throws HongsException {
    Select ann = (Select) anno;
    String conf = ann.conf();
    String form = ann.form();
    byte mode = ann.mode();
    if (mode == -1) {
        Set ab = Synt.toTerms(helper.getRequestData().get(Cnst.AB_KEY));
        if (ab != null) {
            if (ab.contains("!enum")) {
                mode = 0;
            } else {
                if (ab.contains(".enum")) {
                    mode += 1;
                }
                if (ab.contains("_enum")) {
                    mode += 2;
                }
                if (ab.contains("_time")) {
                    mode += 4;
                }
                if (ab.contains("_link")) {
                    mode += 8;
                }
                if (mode >= 0) {
                    mode += 1;
                }
            }
        }
    }
    // 为 0 则不执行, 仅取 enum 数据
    Map rsp;
    if (mode == 0) {
        mode = 1;
        rsp = new HashMap();
    } else if (mode == -1) {
        chains.doAction();
        return;
    } else {
        chains.doAction();
        rsp = helper.getResponseData();
        if (!Synt.declare(rsp.get("ok"), false)) {
            return;
        }
    }
    // 识别路径
    if (form.length() == 0) {
        form = chains.getEntity();
    }
    if (conf.length() == 0) {
        conf = chains.getModule();
        // 照顾 Module Action 的配置规则
        if (FormSet.hasConfFile(conf + "/" + form)) {
            conf = conf + "/" + form;
        }
    }
    // 填充数据
    try {
        Map data = (Map) helper.getAttribute("form:" + conf + "." + form);
        if (data == null) {
            data = FormSet.getInstance(conf).getForm(form);
        }
        SelectHelper sup;
        sup = new SelectHelper().addItemsByForm(conf, data);
        sup.select(rsp, mode);
    } catch (HongsException ex) {
        int ec = ex.getErrno();
        if (ec != 0x10e8 && ec != 0x10e9 && ec != 0x10ea) {
            throw ex;
        }
    }
    // 返回数据
    helper.reply(rsp);
}
Also used : Set(java.util.Set) FormSet(app.hongs.action.FormSet) HashMap(java.util.HashMap) HongsException(app.hongs.HongsException) Map(java.util.Map) HashMap(java.util.HashMap) SelectHelper(app.hongs.action.SelectHelper)

Aggregations

FormSet (app.hongs.action.FormSet)2 SelectHelper (app.hongs.action.SelectHelper)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 HongsException (app.hongs.HongsException)1 ActionRunner (app.hongs.action.ActionRunner)1 SpreadHelper (app.hongs.action.SpreadHelper)1 Action (app.hongs.action.anno.Action)1 Model (app.hongs.db.Model)1 SearchAction (app.hongs.dh.search.SearchAction)1 Data (app.hongs.serv.matrix.Data)1