Search in sources :

Example 1 with Data

use of app.hongs.serv.matrix.Data in project HongsCORE by ihongs.

the class DataAction method acting.

@Override
public void acting(ActionHelper helper, ActionRunner runner) throws HongsException {
    super.acting(helper, runner);
    String ent = runner.getEntity();
    String mod = runner.getModule();
    Method met = runner.getMethod();
    // 绑定特制的表单
    if (met.isAnnotationPresent(Select.class) || met.isAnnotationPresent(Spread.class) || met.isAnnotationPresent(Verify.class)) {
        Data dat = (Data) getEntity(helper);
        Map fcs = dat.getFields();
        helper.setAttribute("form:" + mod + "." + ent, fcs);
    }
    // 放入当前用户ID
    Object uid = helper.getSessibute(Cnst.UID_SES);
    helper.getRequestData().put("user_id", uid);
    helper.getRequestData().put("form_id", ent);
}
Also used : Data(app.hongs.serv.matrix.Data) Method(java.lang.reflect.Method) Verify(app.hongs.action.anno.Verify) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Data

use of app.hongs.serv.matrix.Data in project HongsCORE by ihongs.

the class DataAction method export.

@Action("stream")
@Preset(conf = "", form = "")
@CustomReplies
public void export(ActionHelper helper) throws HongsException, IOException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    String ent = runner.getEntity();
    String mod = runner.getModule();
    Data sr = (Data) getEntity(helper);
    Map rd = helper.getRequestData();
    rd = getReqMap(helper, sr, "export", rd);
    int rn = Synt.declare(rd.get("rn"), 0);
    int pn = Synt.declare(rd.get("pn"), 0);
    Loop lp = sr.search(rd, pn, rn);
    /**
     * 逐行输出
     */
    HttpServletResponse rs = helper.getResponse();
    String csv = ent + "_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
    rs.setHeader("Content-Disposition", "attachment;filename=" + csv + ".csv");
    rs.setHeader("Content-Type", "application/octet-stream;charset=UTF-8");
    rs.setHeader("Transfer-Encoding", "chunked");
    Writer ot = rs.getWriter();
    Map fs = sr.getFields();
    Map es = new HashMap();
    if (lp.hasNext()) {
        Map<String, Object> ds = lp.next();
        StringBuilder sf = new StringBuilder();
        StringBuilder sb = new StringBuilder();
        Map ts = FormSet.getInstance("default").getEnum("__types__");
        for (Map.Entry<String, Object> et : ds.entrySet()) {
            Object fv = et.getValue();
            String fn = et.getKey();
            Map mt = (Map) fs.get(fn);
            Map ex = null;
            String fx, ft;
            fx = (String) mt.get("__text__");
            ft = (String) mt.get("__type__");
            ft = (String) ts.get(ft);
            if ("enum".equals(ft)) {
                String xonf = (String) mt.get("conf");
                String xame = (String) mt.get("enum");
                if (null == xonf || "".equals(xonf))
                    xonf = mod;
                if (null == xame || "".equals(xame))
                    xame = fn;
                ex = FormSet.getInstance(xonf).getEnum(xame);
                es.put(fn, ex);
            }
            sf.append(",\"").append(escape(fx, null)).append("\"");
            sb.append(",\"").append(escape(fv, ex)).append("\"");
        }
        ot.write(sf.append("\r\n").substring(1));
        ot.write(sb.append("\r\n").substring(1));
        ot.flush();
    }
    while (lp.hasNext()) {
        Map<String, Object> ds = lp.next();
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, Object> et : ds.entrySet()) {
            Object fv = et.getValue();
            String fn = et.getKey();
            Map ex = (Map) es.get(fn);
            sb.append(",\"").append(escape(fv, ex)).append("\"");
        }
        ot.write(sb.append("\r\n").substring(1));
    }
}
Also used : ActionRunner(app.hongs.action.ActionRunner) Loop(app.hongs.dh.lucene.LuceneRecord.Loop) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) Data(app.hongs.serv.matrix.Data) Date(java.util.Date) HashMap(java.util.HashMap) Map(java.util.Map) SimpleDateFormat(java.text.SimpleDateFormat) Writer(java.io.Writer) Action(app.hongs.action.anno.Action) SearchAction(app.hongs.dh.search.SearchAction) Preset(app.hongs.action.anno.Preset) CustomReplies(app.hongs.action.anno.CustomReplies)

Example 3 with Data

use of app.hongs.serv.matrix.Data in project HongsCORE by ihongs.

the class DataAction method redo.

@Action("revert/update")
@CommitSuccess
public void redo(ActionHelper helper) throws HongsException {
    String id = helper.getParameter(Cnst.ID_KEY);
    if (null == id || "".equals(id)) {
        throw new HongsException(0x1100, "id required");
    }
    Data sr = (Data) getEntity(helper);
    Map rd = helper.getRequestData();
    sr.redo(id, rd);
    helper.reply("");
}
Also used : HongsException(app.hongs.HongsException) Data(app.hongs.serv.matrix.Data) HashMap(java.util.HashMap) Map(java.util.Map) Action(app.hongs.action.anno.Action) SearchAction(app.hongs.dh.search.SearchAction) CommitSuccess(app.hongs.action.anno.CommitSuccess)

Example 4 with Data

use of app.hongs.serv.matrix.Data 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 5 with Data

use of app.hongs.serv.matrix.Data in project HongsCORE by ihongs.

the class DataAction method acting.

@Override
public void acting(ActionHelper helper, ActionRunner runner) throws HongsException {
    super.acting(helper, runner);
    String ent = runner.getEntity();
    String mod = runner.getModule();
    Method met = runner.getMethod();
    // 绑定特制的表单
    if (met.isAnnotationPresent(Select.class) || met.isAnnotationPresent(Spread.class) || met.isAnnotationPresent(Verify.class)) {
        Data dat = (Data) getEntity(helper);
        Map fcs = dat.getFields();
        helper.setAttribute("form:" + mod + "." + ent, fcs);
    }
    // 放入当前用户ID
    Object uid = helper.getSessibute(Cnst.UID_SES);
    helper.getRequestData().put("user_id", uid);
    helper.getRequestData().put("form_id", ent);
}
Also used : Data(app.hongs.serv.matrix.Data) Method(java.lang.reflect.Method) Verify(app.hongs.action.anno.Verify) Map(java.util.Map)

Aggregations

Data (app.hongs.serv.matrix.Data)5 Map (java.util.Map)5 HashMap (java.util.HashMap)4 Action (app.hongs.action.anno.Action)3 SearchAction (app.hongs.dh.search.SearchAction)3 ActionRunner (app.hongs.action.ActionRunner)2 Verify (app.hongs.action.anno.Verify)2 Method (java.lang.reflect.Method)2 HongsException (app.hongs.HongsException)1 FormSet (app.hongs.action.FormSet)1 SelectHelper (app.hongs.action.SelectHelper)1 SpreadHelper (app.hongs.action.SpreadHelper)1 CommitSuccess (app.hongs.action.anno.CommitSuccess)1 CustomReplies (app.hongs.action.anno.CustomReplies)1 Preset (app.hongs.action.anno.Preset)1 Model (app.hongs.db.Model)1 Loop (app.hongs.dh.lucene.LuceneRecord.Loop)1 Writer (java.io.Writer)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1