|
|
@@ -18,10 +18,10 @@ public abstract class AbstractCompService { |
|
|
|
public final static String TYPE_SAVE = "save"; |
|
|
|
public final static String TYPE_DEL = "del"; |
|
|
|
|
|
|
|
protected abstract IHandler createHandler(String type); |
|
|
|
protected abstract AbstractHandler createHandler(String type); |
|
|
|
|
|
|
|
protected IHandler getHandler(SwMap params, UserSession us, String type) throws Exception { |
|
|
|
IHandler handler = createHandler(type); |
|
|
|
protected AbstractHandler getHandler(SwMap params, UserSession us, String type) throws Exception { |
|
|
|
AbstractHandler handler = createHandler(type); |
|
|
|
if (handler == null) throw new SwException("暂不支持此类服务:" + type); |
|
|
|
if (params == null) params = new SwMap(); |
|
|
|
if (us == null) us = UserSession.createSys(); |
|
|
@@ -29,10 +29,10 @@ public abstract class AbstractCompService { |
|
|
|
return handler; |
|
|
|
} |
|
|
|
|
|
|
|
protected R pageHandler(SwMap params, UserSession us, String type) { |
|
|
|
protected R pageHandler(SwMap params, UserSession us, String type, IWorker worker) { |
|
|
|
try { |
|
|
|
IHandler handler = getHandler(params, us, type); |
|
|
|
return handler.doWork(); |
|
|
|
AbstractHandler handler = getHandler(params, us, type); |
|
|
|
return worker.doWork(handler); |
|
|
|
} catch (Exception e) { |
|
|
|
return R.error("操作失败!", e); |
|
|
|
} |
|
|
@@ -40,81 +40,56 @@ public abstract class AbstractCompService { |
|
|
|
|
|
|
|
//保存 |
|
|
|
public R save(@SwBody SwMap params, UserSession us) { |
|
|
|
return pageHandler(params, us, TYPE_SAVE); |
|
|
|
return pageHandler(params, us, TYPE_SAVE, handler -> ((AbstractSaveHandler)handler).save()); |
|
|
|
} |
|
|
|
|
|
|
|
//树,换爹 |
|
|
|
public R trcp(@SwBody SwMap params, UserSession us) { |
|
|
|
try { |
|
|
|
DefaultSaveHandler handler = (DefaultSaveHandler) getHandler(params, us, TYPE_SAVE); |
|
|
|
return handler.changeParent(); |
|
|
|
} catch (Exception e) { |
|
|
|
return R.error("操作失败!", e); |
|
|
|
} |
|
|
|
return pageHandler(params, us, TYPE_SAVE, handler -> ((AbstractSaveHandler)handler).changeParent()); |
|
|
|
} |
|
|
|
|
|
|
|
//读取 |
|
|
|
public R load(@SwBody SwMap params, UserSession us) { |
|
|
|
return pageHandler(params, us, TYPE_LOAD); |
|
|
|
return pageHandler(params, us, TYPE_LOAD, handler -> ((AbstractLoadHandler)handler).load()); |
|
|
|
} |
|
|
|
|
|
|
|
//删除 |
|
|
|
public R del(@SwBody SwMap params, UserSession us) { |
|
|
|
return pageHandler(params, us, TYPE_DEL); |
|
|
|
return pageHandler(params, us, TYPE_DEL, handler -> ((AbstractDelHandler)handler).del()); |
|
|
|
} |
|
|
|
|
|
|
|
//列表数据 |
|
|
|
public R list(@SwBody SwMap params, UserSession us) { |
|
|
|
return pageHandler(params, us, TYPE_LIST); |
|
|
|
return pageHandler(params, us, TYPE_LIST, handler -> ((AbstractListHandler)handler).listData()); |
|
|
|
} |
|
|
|
|
|
|
|
//列表总记录数及合计栏 |
|
|
|
public R listTotal(@SwBody SwMap params, UserSession us) { |
|
|
|
try { |
|
|
|
AbstractListHandler handler = (AbstractListHandler) getHandler(params, us, TYPE_LIST); |
|
|
|
return handler.getTotal(); |
|
|
|
} catch (Exception e) { |
|
|
|
return R.error("操作失败!", e); |
|
|
|
} |
|
|
|
return pageHandler(params, us, TYPE_LIST, handler -> ((AbstractListHandler)handler).getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
//combo数据 |
|
|
|
public R combo(@SwBody SwMap params, UserSession us) { |
|
|
|
return pageHandler(params, us, TYPE_COMBO); |
|
|
|
return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler)handler).listData()); |
|
|
|
} |
|
|
|
|
|
|
|
//combo总记录数及合计栏 |
|
|
|
public R comboTotal(@SwBody SwMap params, UserSession us) { |
|
|
|
try { |
|
|
|
AbstractListHandler handler = (AbstractListHandler) getHandler(params, us, TYPE_COMBO); |
|
|
|
return handler.getTotal(); |
|
|
|
} catch (Exception e) { |
|
|
|
return R.error("操作失败!", e); |
|
|
|
} |
|
|
|
return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler)handler).getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
//combo数据过滤 |
|
|
|
public R comboFilter(@SwBody SwMap params, UserSession us) { |
|
|
|
try { |
|
|
|
DefaultComboHandler handler = (DefaultComboHandler) getHandler(params, us, TYPE_COMBO); |
|
|
|
return handler.filter(); |
|
|
|
} catch (Exception e) { |
|
|
|
return R.error("操作失败!", e); |
|
|
|
} |
|
|
|
return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler)handler).filter()); |
|
|
|
} |
|
|
|
|
|
|
|
//树数据 |
|
|
|
public R tree(@SwBody SwMap params, UserSession us) { |
|
|
|
return pageHandler(params, us, TYPE_TREE); |
|
|
|
return pageHandler(params, us, TYPE_COMBO, handler -> ((AbstractTreeHandler<Object>)handler).data()); |
|
|
|
} |
|
|
|
|
|
|
|
//树过滤 |
|
|
|
public R treeFilter(@SwBody SwMap params, UserSession us) { |
|
|
|
try { |
|
|
|
AbstractTreeHandler handler = (AbstractTreeHandler) getHandler(params, us, TYPE_TREE); |
|
|
|
return handler.filter(); |
|
|
|
} catch (Exception e) { |
|
|
|
return R.error("操作失败!", e); |
|
|
|
} |
|
|
|
return pageHandler(params, us, TYPE_COMBO, handler -> ((AbstractTreeHandler<Object>)handler).filter()); |
|
|
|
} |
|
|
|
} |