Search in sources :

Example 6 with ActionRunner

use of io.github.ihongs.action.ActionRunner in project HongsCORE by ihongs.

the class TitlesHelper method addForks.

/**
 * 通过调用关联动作来补全名称
 * @param ls
 * @param fc
 * @param fn
 * @throws HongsException
 */
protected void addForks(List<Object[]> ls, Map fc, String fn) throws HongsException {
    String at = (String) fc.get("data-at");
    String vk = (String) fc.get("data-vk");
    String tk = (String) fc.get("data-tk");
    if (at == null || at.isEmpty()) {
        String c = (String) fc.get("conf");
        String f = (String) fc.get("form");
        at = c + "/" + f + "/search";
    }
    if (vk == null || vk.isEmpty()) {
        vk = Cnst.ID_KEY;
    }
    if (tk == null || tk.isEmpty()) {
        tk = "name";
    }
    Object[] vk2 = Dict.splitKeys(vk);
    Object[] tk2 = Dict.splitKeys(tk);
    // 映射关系
    Map<Object, Object[]> lm = new HashMap();
    for (Object[] lx : ls) {
        lm.put(lx[0], lx);
    }
    Set li = lm.keySet();
    // 查询结构
    Map cd = new HashMap();
    Map rd = new HashMap();
    Set rb = new HashSet();
    rd.put(Cnst.RB_KEY, rb);
    rd.put(Cnst.RN_KEY, 1024);
    rb.add(vk);
    rb.add(tk);
    // 获取结果
    ActionHelper ah = ActionHelper.newInstance();
    ah.setContextData(cd);
    ah.setRequestData(rd);
    ActionRunner ar = ActionRunner.newInstance(ah, at);
    /**
     * Lucene 单个条件的数量无法超过 1024
     * 故需拆成片段
     * 分批进行查询
     */
    List l = new ArrayList(li);
    int k = l.size();
    int j = 0, i = 0;
    while (j < k) {
        j = i + 1024;
        if (j > k) {
            j = k;
        }
        rd.put(Cnst.ID_KEY, l.subList(i, j));
        /**/
        i = j;
        ar.doInvoke();
        // 整合数据
        Map sd = ah.getResponseData();
        List<Map> lz = (List) sd.get("list");
        if (lz != null)
            for (Map ro : lz) {
                String lv = Dict.getValue(ro, "", vk2);
                String lt = Dict.getValue(ro, "", tk2);
                Object[] lx = lm.get(lv);
                if (null != lx) {
                    lx[1] = lt;
                }
            }
    }
}
Also used : ActionRunner(io.github.ihongs.action.ActionRunner) FormSet(io.github.ihongs.action.FormSet) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActionHelper(io.github.ihongs.action.ActionHelper) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 7 with ActionRunner

use of io.github.ihongs.action.ActionRunner in project HongsCORE by ihongs.

the class DBAction method getRspMsg.

/**
 * 获取返回消息
 * @param helper
 * @param ett
 * @param opr
 * @param num
 * @return
 * @throws HongsException
 */
protected String getRspMsg(ActionHelper helper, Model ett, String opr, int num) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    String mod = runner.getModule();
    String ent = runner.getEntity();
    String cnt = Integer.toString(num);
    CoreLocale locale = CoreLocale.getInstance().clone();
    locale.fill(mod);
    String key = "fore." + opr + "." + ent + ".success";
    if (!locale.containsKey(key)) {
        key = "fore." + opr + /**/
        ".success";
    }
    return locale.translate(key, null, cnt);
}
Also used : ActionRunner(io.github.ihongs.action.ActionRunner) CoreLocale(io.github.ihongs.CoreLocale)

Aggregations

ActionRunner (io.github.ihongs.action.ActionRunner)7 Data (io.github.ihongs.serv.matrix.Data)3 CoreLocale (io.github.ihongs.CoreLocale)2 ActionHelper (io.github.ihongs.action.ActionHelper)2 Map (java.util.Map)2 Set (java.util.Set)2 Core (io.github.ihongs.Core)1 HongsException (io.github.ihongs.HongsException)1 HongsExemption (io.github.ihongs.HongsExemption)1 FormSet (io.github.ihongs.action.FormSet)1 SelectHelper (io.github.ihongs.action.SelectHelper)1 Action (io.github.ihongs.action.anno.Action)1 SearchAction (io.github.ihongs.dh.search.SearchAction)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1